我正在使用postgresql 设计使用downcase在db中存储电子邮件: config.case_insensitive_keys = [:email]
但是当我使用大写的电子邮件登录时 - 我收到错误,电子邮件错误。 我找到了这个问题,但这有一个麻烦:
def self.find_for_authentication(conditions = {})
# Allow to log in with case insensitive email
conditions[:email].downcase!
end
1)当我尝试使用错误的大写电子邮件登录时,我收到错误,我的电子邮件是小写的。 (以AAA@bbb.CCC登录,获得aaa@bbb.ccc,但我需要显示AAA@bbb.CCC)。我该如何改变这种行为?
答案 0 :(得分:0)
我不确定我能帮您,但您应该可以访问原始电子邮件 由
提供条件[:电子邮件]
或者一旦登录,您就可以通过登录用户的电子邮件访问 self.email。
如果有帮助,请告诉我
答案 1 :(得分:0)
解决方案非常简单。你需要的只是复制params hash并在登录时更改此哈希中的电子邮件,但是当用户获得异常时 - 我们只返回带有输入参数的原始哈希
def self.find_for_authentication(conditions = {})
# Allow to log in with case insensitive email
new_hash = conditions.dup
new_hash[:email] = conditions[:email].downcase
where(new_hash).first
end