Reputation: 11687
I have a model:
class Shirt < ActiveRecord::Base
named_scope :red, :conditions => { :color => 'red' }
named_scope :blue, :conditions => { :color => 'blue' }
named_scope :xl, :conditions => { :size => 'xl' }
end
I forgot, how to easy add named scope to existing anonymous scope:
scope = Shirt.scoped({})
#and how to add ie. :red to scope?
Upvotes: 2
Views: 210
Reputation: 44016
This can be achieved with the following code:
named_scope :colour, lambda { |colour_id| {:conditions => ["colour_id = ?", colour_id])}}
You can chain named scopes:
Shirt.red.xl
Upvotes: 0