2

我正在尝试添加一个名为 username 的属性来设计,但 rails 在以下代码行中显示错误我正在使用 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
  # 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
4

2 回答 2

2

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

于 2015-04-17T23:11:09.837 回答
1

You mistyped a comma before if:

before_action :configure_permitted_parameters, if: :devise_controller?
于 2015-04-17T23:11:27.440 回答