Skip to content
This repository has been archived by the owner on Aug 17, 2017. It is now read-only.

Rails 4 migration clarification #226

Open
scottjacobsen opened this issue Jul 15, 2015 · 1 comment
Open

Rails 4 migration clarification #226

scottjacobsen opened this issue Jul 15, 2015 · 1 comment

Comments

@scottjacobsen
Copy link

The Rails 4 migration section of the documentation says to remove attr_accessible and attr_protected from the models being migrated. This will only work if you disable default whitelisting by setting:

config.active_record.whitelist_attributes = false

If default whitelisting is enable I found I need to disable the whitelist on a per model basis like this:

class Post < ActiveRecord::Base
   attr_protected # disable whitelist for this model
   include ActiveModel::ForbiddenAttributesProtection
end

Isn't it safer to keep default whitelisting enabled and disable only after the full migration is finished?

@mattbrictson
Copy link

@scottjacobsen Thanks for mentioning this! I was stuck trying to figure out why the migration instructions were not working for me. I like your suggestion, which would make the steps:

  • Work one model at a time
  • First add include ActiveModel::ForbiddenAttributesProtection
  • And add attr_protected
  • Verify controller/integration tests fail
  • Fix by using require and permit
  • Move on to the next model

Then set config.active_record.whitelist_attributes = false once the migration is complete.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants