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,
--
Posted via http://www.ruby-forum.com/.
This is a correct way to do it now. And probably the best way to move forward
with the tutorial right now. The newest releases of Rails have made
mass-assign protection the default. Without it you have a security risk. You
can learn more by Googling "Rails mass assign". Save it for after you
complete the book.
HTH,
Jeffrey
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
===============================================================================
Tom - I tried google first (I always do). My attributes are already set
to attr_accessible in my models (there are only three at this point),
which is why I was so confused. I'm sure there's something I'm
overlooking but I'm not going to spend too much more time on it since I
have a working solution at this point.