2017-01-16 49 views
1

initializers/devise.rb下面的配置基于不起作用:查找不区分大小写的电子邮件在设计

# Configure which authentication keys should be case-insensitive. # These keys will be downcased upon creating or modifying a user and when used # to authenticate or find a user. Default is :email. config.case_insensitive_keys = [:email]

什么“查找用户”是什么意思?它在干什么时:

User.find_by(email: "[email protected]")

因为不工作,返回nil时,我有与数据库中的电子邮件"[email protected]"用户。

im使用导轨5和设计4.2.0

回答

1

注意User.find_by(email: params[:email])是大小写敏感的。改为使用User.find_for_authentication(email: params[:email])。见docs

+0

这是有效的。没有看到[文档](https://github.com/plataformatec/devise/wiki/How-To:-Use-case-insensitive-emails)。谢谢! – puerile