1
如何使用OR將這兩個示波器合併爲一個。像其中任何一個都可以是真的。Ruby on rails範圍如OR
scope :search_language, lambda {|y| where(["language LIKE ?", "#{y}"])}
scope :search_published, lambda {|y| where(["published LIKE ?", "#{y}"])}
如何使用OR將這兩個示波器合併爲一個。像其中任何一個都可以是真的。Ruby on rails範圍如OR
scope :search_language, lambda {|y| where(["language LIKE ?", "#{y}"])}
scope :search_published, lambda {|y| where(["published LIKE ?", "#{y}"])}
您可以將兩者結合成一個單一的查詢爲:
scope :language_or_published, lambda { |y| where('language like ? or published like ?', y, y) }
或拉姆達的新形式(Ruby1.9後):
scope :language_or_published, ->(y){ where('language like ? or published like ?', y, y) }
您可以添加'範圍:search_language_or_published,lambda {| y |其中([「語言喜歡?或已發佈喜歡?」,「#{y}」,「#{y}」])} – Sasidaran