开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜