简体   繁体   English

Rails存在?不区分大小写

[英]Rails exists? Case insensitive

Model.exists?("lower(email) = ?", params[:email].downcase)

Returns error: ArgumentError (wrong number of arguments (2 for 0..1)): 返回错误: ArgumentError (wrong number of arguments (2 for 0..1)):

Is it possible to do a exists? 是否有可能exists? with a case insensitive match? 不区分大小写的匹配?

All you need to do is this: 你需要做的就是:

Model.exists?(["lower(email) = ?", params[:email].downcase])

It's looking for a single argument but you're providing two. 它正在寻找一个单一的论点,但你提供两个。 Using the array form and the find-style conditional should get what you need. 使用数组表单和查找样式条件应该得到你需要的。

你也可以这样做:

Model.where("lower(email) = ?",params[:email].downcase).exists?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM