On Apr 8, 2012, at 1:14 , Lucas J. wrote:
> I am new to Ruby and to Rails (using Ruby 1.9.3 and Rails 3.2.3) so I
> picked up the Agile Web Development book and have been working through
> it (apologies if this isn't the correct place for this question but the
> pragprog forums don't seem to work for me). I am currently working
> through the book and have reached the point where I am adding
> functionality to an "Add to Cart" button. Here is the code that was
> provided for the 'create' method in the line_item_controller:
>
> def create
>
> @cart = current_cart
> product = Product.find(params[:product_id])
> @line_item = @cart.line_items.build(product: product)
>
> ...
>
> end
>
> This results in the following error when I click "Add to Cart"
>
> Can't mass-assign protected attributes: product
>
> Can anyone shed some light on what is going on here (my search-fu has
> failed me)? The only way that I have been able to get this to work is
> by changing the code (starting at @line_item) to:
>
> @line_item = @cart.line_items.build
> @line_item.product = product
>
> Is this correct or is it just a band-aid fix that may cause issues going
> forward?
>
> Thanks,
what about use google a bit? there's about 2.460.000 resuls for "Can't
mass-assign protected attributes:" query
set attr_accessible in your model(s)
tom
--
===============================================================================
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache
www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz
===============================================================================
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.