Come up with: Missing options

I don’t know why, but the following code just stops working (I didn’t even notice how it happened)

routes.rb

devise_for :users, components: {registrations: 'registrations', sessions: 'sessions'} 

registations_controller.rb

 class RegistrationsController < Devise::RegistrationsController before_filter :configure_permitted_parameters def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up).push(:name, :surname, :username, :email, :avatar) devise_parameter_sanitizer.for(:account_update).push(:name, :surname, :email, :avatar) end end 

As I said, everything worked fine, but now I get:

 Processing by Devise::RegistrationsController#create as HTML Parameters: {"utf8"=>"βœ“", "authenticity_token"=>"lvuPOmTRqv6XUQ/O1g4Q9VNvzD7DgGCHocY/OlAvKHEIvWAHvlS982hxSZZzzAESCpmL5QTUcTLw/c9ME/sUFQ==", "user"=>{"name"=>"John", "surname"=>"Doe", "username"=>"foobar", "email"=>" foobar@example.com ", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Register"} Unpermitted parameters: name, surname, email 

configuration *:

  • Rails 4.2.5
  • Develop 3.5.6

PS: Now I understand why I should cover my code with unit tests and use Travis CI

+6
source share
2 answers

I think you should try "configure_permitted_parameters" in the application controller instead of the registration controller.

 class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up).push(:name, :surname,:username, :email, :avatar) devise_parameter_sanitizer.for(:account_update).push(:name, :surname, :email, :avatar) end end 
+6
source

The for method has been deprecated since version 4.1. Use this instead:

 class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters attributes = [:name, :surname,:username, :email, :avatar] devise_parameter_sanitizer.permit(:sign_up, keys: attributes) devise_parameter_sanitizer.permit(:account_update, keys: attributes) end end 
+7
source

All Articles