Rails 4 + Devise 3.0.0添加用户名

问题描述:

我正在使用Rails 4和Devise 3.0.0,并且是使用这些新的强大参数的新手。我使用 Devise wiki上的文档。我遇到的问题是Rails 4中的强参数变化。

I'm working with Rails 4 and Devise 3.0.0 and am new to using these new strong paramters. I added a username to the User model using the documentation on the Devise wiki. The problem I'm running into is the strong parameters change in Rails 4.

如何添加:login 属性到用户模型以启用使用用户名或电子邮件登录?

How do I add the :login attribute to the user model to enable logging in with either the username or email?

从devise的rails4自述文件: a href =https://github.com/plataformatec/devise/tree/rails4#strong-parameters =noreferrer> https://github.com/plataformatec/devise/tree/rails4#strong-parameters

From the rails4 readme on devise: https://github.com/plataformatec/devise/tree/rails4#strong-parameters

class ApplicationController < ActionController::Base
  before_filter :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :email) }
  end
end