ruby-on-railsruby-on-rails-3ruby-on-rails-4strong-parametersattr-accessible

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.


Solution

  • 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.