【问题标题】:undefined local variable or method `resource_class' in devise设计中未定义的局部变量或方法“resource_class”
【发布时间】:2015-06-24 23:37:45
【问题描述】:

我正在尝试添加一个名为 username 的属性来设计,但 rails 在以下代码行中显示错误 我正在使用 rails 4.0.0 并设计 3

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

控制器应用程序

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

【问题讨论】:

    标签: ruby-on-rails devise ruby-on-rails-4.1 rails-4-2-1


    【解决方案1】:

    试试:

    before_action :configure_permitted_parameters, if: :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

    【讨论】:

      【解决方案2】:

      你在 if 之前打错了逗号:

      before_action :configure_permitted_parameters, if: :devise_controller?
      

      【讨论】:

      • BearGrylls before_action :configure_permitted_pa​​rameters,如果::devise_controller?工作
      • before_action :configure_permitted_pa​​rameters,如果 :devise_controller?没用
      • 可以是我的设计版本吗?
      • 好的,非常感谢朋友
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-03
      • 1970-01-01
      • 1970-01-01
      • 2017-01-26
      相关资源
      最近更新 更多