如何使用"用户名或电子邮件",登录设计?

Hem*_*nth 5 authentication ruby-on-rails ruby-on-rails-plugins devise ruby-on-rails-3

我找到了一种方法来自定义设备使用用户名登录而不是电子邮件地址.
但实际上我想使用组合: -

Enter username or Email:   <text-box>
Enter your password    :   <text-box>  
Run Code Online (Sandbox Code Playgroud)

那么如何实现呢?

实际上我们需要修改devise gem的配置来支持它.
现在我知道修改"/config/initializers/devise.rb"文件为

config.authentication_keys = [ :username ] (edited from email to username.)  
Run Code Online (Sandbox Code Playgroud)

实际上会使用username而不是emailid启用登录.
但我可以做一些事情: -

config.authentication_keys = [ :username | :email] in the "config/initializers/devise.rb" file.  
Run Code Online (Sandbox Code Playgroud)

因此,我们设计可以在运行时将用户名或电子邮件作为身份验证密钥,具体取决于用户提供的输入.
提前致谢 .

Ark*_*kan 14

请看那里:https://github.com/plataformatec/devise/wiki/How-To : -Allow -users-to-sign-in-using-their-username-or-email- address(url updated)

它解释了如何允许用户使用他们的用户名或电子邮件地址登录.