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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -