0

如果我单击注销按钮,我会收到此错误:检查结果必须仅为 ASCII 或使用与默认外部相同的编码

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.

  before_action :authenticate_user!
  before_action :configure_permitted_parameters, if: :devise_controller?

  protect_from_forgery with: :exception

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email) }
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :password, :password_confirmation) }
    devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:username, :email, :password, :password_confirmation, :current_password) }
  end

end

关联:

<%= link_to "Logout", logout_path, title: "Logout", method: :delete %>

路线:

devise_scope :user do
  get 'register', to: 'devise/registrations#new', as: 'register'
  get 'login', to: 'devise/sessions#new', as: 'login'
  delete 'logout', to: 'devise/sessions#destroy', as: 'logout'
end

我不知道问题出在哪里。

如果我删除这 3 行,那么它可以工作,但我无法注册新用户:

devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email) }
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :password, :password_confirmation) }
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:username, :email, :password, :password_confirmation, :current_password) }

谢谢!

4

2 回答 2

0

我不确定这是否是原因,但我注意到您不允许在登录时将密码列入白名单。我认为您会希望这样做,因为您在注册和帐户更新中输入了密码。它应该看起来像这样

devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email, :password) }
于 2013-11-29T18:04:59.340 回答
0

尝试使用以下

devise_parameter_sanitizer.for(:sign_up) << :username

如果您还需要另一个字段,请添加与上面类似的行

于 2013-11-15T20:25:09.780 回答