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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With