未定义的局部变量或方法`resource_class'在设计中 [英] undefined local variable or method `resource_class' in devise
本文介绍了未定义的局部变量或方法`resource_class'在设计中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用rails 4.0.0和devise 3
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up){| u | u.permit(:username,:email,:password,,password_confirmation)}
end
控制器应用程序
class ApplicationController< ActionController :: Base
#通过引发异常来防止CSRF攻击。
#对于API,您可能需要使用:null_session。
protect_from_forgery with::exception
before_action:configure_permitted_parameters if:devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up){| u | u.permit(:username,:email,:password,,password_confirmation)}
end
end
解决方案
尝试:
before_action:configure_permitted_parameters,如果::devise_controller?
或
before_action:configure_permitted_parameters,if => :devise_controller?
参考: https://github.com/plataformatec/devise/issues/2372 & http://guides.rubyonrails.org/active_record_callbacks.html#conditional-callbacks
I am trying add a attribute called username to devise but rails shows me an error in the following line of code I am using rails 4.0.0 and devise 3
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :password, :password_confirmation) }
end
Controller application
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_action :configure_permitted_parameters if :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :password, :password_confirmation) }
end
end
解决方案
Try:
before_action :configure_permitted_parameters, if: :devise_controller?
or
before_action :configure_permitted_parameters, :if => :devise_controller?
Ref: https://github.com/plataformatec/devise/issues/2372 & http://guides.rubyonrails.org/active_record_callbacks.html#conditional-callbacks
这篇关于未定义的局部变量或方法`resource_class'在设计中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文