Ruby on rails 设计命名器&x27;对于';参数消毒剂
每次我在网上唱歌时都会犯一个错误,我快发疯了 Heroku日志:Ruby on rails 设计命名器&x27;对于';参数消毒剂,ruby-on-rails,ruby,heroku,devise,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:
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'
2016-07-06 01:35:03+0000时201.235.89.150的开始获取“/用户/登录”
在3毫秒内完成500个内部服务器错误(ActiveRecord:0.0毫秒)
NoMethodError(用于#的未定义方法'for'):
app/controllers/application\u controller.rb:11:在“配置允许的参数”中
应用程序\u 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
class ApplicationController
问题是它在本地运行良好。就在希罗库。几天前,它还工作得很好。class ApplicationControllerclass 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
在\u操作之前:配置\u允许的\u参数,如果::设计\u控制器?
受保护的
def配置\u允许的\u参数
设计参数消毒剂。许可证(:注册,按键:[:名字,:姓氏,:电子邮件])
设计参数消毒器。许可证(:帐户更新,密钥:[:名字,:姓氏,:电话,:电子邮件,银行属性:[:银行名称,:银行帐户]])
结束
结束
“4.1+中不推荐使用.for方法”
第一个参数是操作名称。:sign\u用于创建新的设计资源(如用户),而:account\u update用于编辑/更新资源
第二个参数:keys包含一个允许的参数数组
如果您想要嵌套的属性,在“帐户更新”中有一个例子,您可以在其中放置一个单独的数组,其中的键是“属性”。看看这个。也许它能帮助你。几天前你说它运行良好,你是说在heroku上?我会尝试在heroku上获得一个新的gemset并重新启动dynos,看看这是否有帮助。在heroku上,我的Desive gem更新为4.2,因此“.for”不再工作。正如@EddeAlmeida所建议的,我改为“.permit”。虽然,现在我有其他的问题。谢谢大家。