Justin Meltzer
Justin Meltzer

Reputation: 13548

How can I do this in a scope?

I have this scope:

scope :search, lambda {|q| where("name LIKE ?", "%#{q}%") }

However, I want to compare q and name irregardless of capitalization. So I can do #{q.downcase} but how can I get name lowercased?

Upvotes: 2

Views: 121

Answers (1)

sepp2k
sepp2k

Reputation: 370162

You can use the SQL lower function:

scope :search, lambda {|q| where("LOWER(name) LIKE ?", "%#{ q.downcase }%") }

Upvotes: 4

Related Questions