为'ParameterSanitizer设计NoMethodError'

时间:2016-07-06 01:45:16

标签: ruby-on-rails ruby heroku devise

我每次尝试在网上唱歌/唱歌时都会遇到错误。

Heroku日志:

Started GET "/users/sign_in" for 201.235.89.150 at 2016-07-06 01:35:03 +0000
 Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `for' for #<Devise::ParameterSanitizer:0x007f5968e0a920>):
 app/controllers/application_controller.rb:11:in `configure_permitted_parameters'

application_controller.rb

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

  before_filter :configure_permitted_parameters, if: :devise_controller?

    protected

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

事情是它在当地运作良好。它只是在Heroku上。而且几天前工作也很好。

1 个答案:

答案 0 :(得分:37)

class ApplicationController < ActionController::Base    
  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, :email])
    devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :phone, :email, bank_attributes: [:bank_name, :bank_account]])
  end
end

“。+方法在4.1 +

中已弃用

第一个arg是动作名称。 :sign_up用于创建新的Devise资源(例如用户),以及:account_update用于编辑/更新资源。

第二个arg:键包含您允许的参数数组。

如果你想要nested_attributes,有一个例子:account_update,你把一个单独的数组放入,其中键是_attributes。“