Warm tip: This article is reproduced from stackoverflow.com, please click
ruby ruby-on-rails devise

Devise: Unpermitted parameters

发布于 2020-03-31 22:55:50

I don't not why, but the following code just stopped working (I didn't even noticed 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, everyting worked fine before, but now I'm getting:

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

Cofiguration:

  • Rails 4.2.5
  • Devise 3.5.6

P.S.: Now I finnaly understand why should I cover my code with unit-tests and use Travis CI

Questioner
Viktor
Viewed
80
5,515 2017-09-19 08:39

I think you should try "configure_permitted_parameters" method in application controller instead of 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