【问题标题】:Finding case-insensitive emails does not work in Devise查找不区分大小写的电子邮件在 Devise 中不起作用
【发布时间】:2017-05-31 00:46:38
【问题描述】:

基于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: "UsEr@ExampLe.com")

因为当我在数据库中有一个电子邮件为"user@example.com" 的用户时,这不起作用并返回 nil。

我正在使用 rails 5 和 Devise 4.2.0

【问题讨论】:

    标签: ruby-on-rails email devise ruby-on-rails-5


    【解决方案1】:

    请注意,User.find_by(email: params[:email]) 区分大小写。请改用User.find_for_authentication(email: params[:email])。见docs

    【讨论】:

    • 那行得通。没看到docs。谢谢!
    猜你喜欢
    • 2020-11-09
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 2020-09-15
    • 2013-06-20
    • 1970-01-01
    • 2012-04-06
    相关资源
    最近更新 更多