Ruby on rails scope like OR -
how can write these 2 scopes in one, or. either of them can true.
scope :search_language, lambda {|y| where(["language ?", "#{y}"])} scope :search_published, lambda {|y| where(["published ?", "#{y}"])}
you combine 2 single query as:
scope :language_or_published, lambda { |y| where('language ? or published ?', y, y) }
or newer form of lambda(post ruby1.9):
scope :language_or_published, ->(y){ where('language ? or published ?', y, y) }
Comments
Post a Comment