Do rails exist? Case insensitive

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

      

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

Is it possible to do exists?

with a case insensitive match?

+3


source to share


2 answers


All you have to do is the following:

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

      



It looks for one argument, but you provide two. Using an array form and a find-style conditional should get what you need.

+9


source


You can also do the following:



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

      

+8


source







All Articles