ActiveModel::MassAssignmentSecurity::Error in LineItemsController#create
Can't mass-assign protected attributes: product Rails.root: /home/lim/work/depot
Application Trace | Framework Trace | Full Trace app/controllers/line_items_controller.rb:45:in `create'
create 方法代码如下 def create @cart = current_cart product=Product.find(params[:product_id]) @line_item = @cart.line_items.build(:product => product)
respond_to do |format| if @line_item.save format.html { redirect_to(@line_item.cart, :notice => 'line item was successfully created.')} format.xml {render :xml => @line_item, :status => :created ,:location => @line_item} else format.html {render :action => "new"} format.xml {render :xml => @line_item.errors, :status => :unprocessable_entity} end end end