Reputation: 7855
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?
Upvotes: 3
Views: 2116
Reputation: 361
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
Upvotes: 5