设计中未定义的局部变量或方法“resource_class”

undefined local variable or method `resource_class' in devise

我正在尝试添加一个名为 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

尝试:

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

您在 if:

之前打错了一个逗号
before_action :configure_permitted_parameters, if: :devise_controller?