Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mass assignment fails when upgrading to Rails 4

deprecated_mass_assignment_security.rb:17:in `attr_accessible': `attr_accessible` is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add `protected_attributes` to your Gemfile to use old one. (RuntimeError)

I tried what the message says, adding gem 'strong_parameters' to my Gemfile.

But when I do rails s I get the error above.

Update

I tried:

config.active_record.whitelist_attributes = true

in confgi/application.rb, also with false, but actually I don't understand that option.

like image 315
sites Avatar asked Jul 29 '13 03:07

sites


2 Answers

attr_accessible and attr_protected have been pulled out of Rails 4 and extracted into protected_attributes. Bundle that into your app and then you should be able to use them again.

That being said, it's recommended that you use strong_parameters instead of attr_accessible these days, so eventually you'll want to migrate to that.

like image 160
Chris Schmitz Avatar answered Nov 02 '22 12:11

Chris Schmitz


In your Gemfile you will notice that gem 'protected_attributes' has been hashed out. Remove the hash. Run bundle install.

But since protected_attributes has been deprecated and may disappear in the future use strong_parameters as mentioned in the above post.

For more info on strong_parameters refer this link.

like image 25
Shine Cardozo Avatar answered Nov 02 '22 10:11

Shine Cardozo