Keyvman
Keyvman

Reputation: 59

How do I make a query search in rails case insensitive?

I have this search method in my user.rb model

def self.search(query)
    where("description like ?", "%#{query}%")
end

but my search is case sensitive. I want to make it case insensitive. How do I do that? I'm hoping it's a quick fix.

Thanks

Upvotes: 0

Views: 287

Answers (1)

Alejandro Babio
Alejandro Babio

Reputation: 5239

Because you are using postgresql:

def self.search(query)
  where("description ilike ?", "%#{query}%")
end

Just use ilike instead of like. like/ilike documentation

If you want to use =, both sides either UPPER or LOWER

Upvotes: 1

Related Questions