如何为 Rails 3 编写不区分大小写的 find_by_email
我发现,如果用户使用电子邮件注册并在电子邮件中使用大写字母,那么当我执行以下操作时,我会得到零。
示例:
username = [email protected]
params[:user][:email] = [email protected]
user = User.find_by_email(params[:user][:email])
user.nil?
=> true
如何在不区分大小写问题的情况下搜索电子邮件,或者如何编写不区分大小写的 find_by_email?
I found that if a user registers with an email and use a capital letter in their email when I do the following I get nil.
Example:
username = [email protected]
params[:user][:email] = [email protected]
user = User.find_by_email(params[:user][:email])
user.nil?
=> true
How can I search for an email without the problems of case sensitivity or how an I write a find_by_email that is case insensitive?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果用户(比如 X)的电子邮件地址为“[电子邮件受保护]” ,然后
应该返回用户 X。我没有复制这种情况,但我想这就是你本质上需要做的。
或者,更好的是,使用 where 而不是 find 正如 @MrTheWalrus 指出的那样
If a user(say X) has an email '[email protected]', then
should return the user X. I didnt replicate the situation but that is what I guess you essentially need to do.
Or, more better, use where instead of find as pointed out by @MrTheWalrus