Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone explain strict mass assignment in Rails 3.2?

I'm just getting up to speed with Rails 3.2, and when I use create or update_attributes, I always seem to get mass assignment errors. Is this normal? How should I be creating and updating records?

like image 373
Nathan Avatar asked Dec 30 '25 01:12

Nathan


1 Answers

add the attributes you want to set via massassignment to the whitelist in the model attr_accessible :my_attribute

allowing to set related nested model-attributes through the same form, you have to set an accepts_nested_attributes_for for this model and add the attributes to the whitelist attr_accessible :$RELATED_MODEL_attributes

read those links. http://api.rubyonrails.org/classes/ActiveModel/MassAssignmentSecurity/ClassMethods.html

http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html

like image 132
mober Avatar answered Dec 31 '25 17:12

mober