RailsApps / rails3-devise-rspec-cucumber

An example Rails 3.2 app with Devise and RSpec and Cucumber.
http://railsapps.github.io/
444 stars 144 forks source link

Rails 4, Devise and strong parameters #49

Open AlexVPopov opened 11 years ago

AlexVPopov commented 11 years ago

If you are using Rails 4 you'll stumble on a problem in the section "Modify the User Model". Adding the line attr_accessible :name, :email, :password, :password_confirmation, :remember_me will cause:

`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) 

To know why, read this. In short, to correct the problem, delete this line from app/models/user.rb and add this code to app/controllers/application_controller.rb:

before_filter :configure_permitted_parameters, if: :devise_controller?

protected

def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) << :name
end

More info about this here.