Rails 5.1
devise 4.3.0
在config / routes.rb中,我有:
devise_for :users, controllers: {
sessions: 'users/sessions',
confirmations: 'users/confirmations',
passwords: 'users/passwords',
registrations: 'users/registrations',
unlocks: 'users/unlocks',
invitations: 'users/invitations'
}
在app / controllers / users / sessions_controller.rb中,我有:
class Users::SessionsController < Devise::SessionsController
before_action :configure_sign_in_params, only: [:create]
def new
super
end
def create
super
end
def destroy
super
end
protected
def configure_sign_in_params
devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
end
end
当我尝试登录时,出现以下错误:
NoMethodError in Users::SessionsController#create
undefined method `concat' for #<Proc:0x00007f634da41ea8>
它指向app / controllers / users / sessions_controller.rb中的这一行,作为错误的来源。
devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
请求参数为:
{"utf8"=>"✓",
"authenticity_token"=>"..........",
"user"=>{"email"=>"myemail@myemail.com", "password"=>"[FILTERED]", "remember_me"=>"0"},
"commit"=>"Log In",
"format"=>"user"}
如果我在控制器中注释掉before_action行,我会收到以下错误:
ActionController::UnknownFormat in Users::SessionsController#create
ActionController::UnknownFormat
Extracted source (around line #11):
def create
super (this would be line 11)
端
相反,如果我点击更改密码,我会通过电子邮件发送一个链接,当我点击它时,它允许我更改密码,我已经登录了。
这是controllers / users / passwordds_controller.rb:
class Users::PasswordsController < Devise::PasswordsController
def new
super
end
def create
super
end
def edit
super
end
def update
super
end
protected
def after_resetting_password_path_for(resource)
super(resource)
end
def after_sending_reset_password_instructions_path_for(resource_name)
super(resource_name)
end
end
在检查configure_sign_in_params方法中的参数时,为什么会失败?