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?
You can use the SQL lower
function:
scope :search, lambda {|q| where("LOWER(name) LIKE ?", "%#{ q.downcase }%") }
精彩评论