如何使用OR将这两个范围合二为一。像其中任何一个都可以是真的。
scope :search_language, lambda {|y| where(["language LIKE ?", "#{y}"])}
scope :search_published, lambda {|y| where(["published LIKE ?", "#{y}"])}
答案 0 :(得分:0)
您可以将两者合并为一个查询:
scope :language_or_published, lambda { |y| where('language like ? or published like ?', y, y) }
或更新形式的lambda(后Ruby1.9):
scope :language_or_published, ->(y){ where('language like ? or published like ?', y, y) }