开发者

How can I do this in a scope?

开发者 https://www.devze.com 2023-03-12 21:08 出处:网络
I have this scope: scope :search, lambda 开发者_开发问答{|q| where(\"name LIKE ?\", \"%#{q}%\") }

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 }%") }
0

精彩评论

暂无评论...
验证码 换一张
取 消