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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
add the attributes you want to set via massassignment to the whitelist in the model
attr_accessible :my_attributeallowing to set related nested model-attributes through the same form, you have to set an
accepts_nested_attributes_forfor this model and add the attributes to the whitelistattr_accessible :$RELATED_MODEL_attributesread those links.
http://api.rubyonrails.org/classes/ActiveModel/MassAssignmentSecurity/ClassMethods.html
http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html