我正在努力,一个错误,我每次尝试在我的网络上唱歌/
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,:current_password) } end end
事情是在当地工作正常.只是在Heroku.而且几天前它工作得很好.
解决方法
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,:phone,bank_attributes: [:bank_name,:bank_account]]) end end
“.for方法在4.1中被弃用
第一个参数是动作名称. :sign_up用于创建新的Devise资源(如用户),并且:account_update用于编辑/更新资源.
第二个参数::keys包含一个你允许的参数的数组.
如果你想要nested_attributes,有一个例子:account_update,你把一个单独的数组放在一起,这个键是_attributes.