Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails exists? Case insensitive

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

Returns error: ArgumentError (wrong number of arguments (2 for 0..1)):

Is it possible to do a exists? with a case insensitive match?

like image 927
Philip Avatar asked May 14 '15 15:05

Philip


2 Answers

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.

like image 101
MCBama Avatar answered Sep 21 '22 00:09

MCBama


You also can do like this:

Model.where("lower(email) = ?",params[:email].downcase).exists?
like image 42
pangpang Avatar answered Sep 22 '22 00:09

pangpang