Philip
Philip

Reputation: 7166

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?

Upvotes: 8

Views: 2252

Answers (2)

MCBama
MCBama

Reputation: 1490

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.

Upvotes: 15

pangpang
pangpang

Reputation: 8821

You also can do like this:

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

Upvotes: 9

Related Questions