Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Ever had the trouble to create a new named_scope out of others? See how it works:
class Fu < ActiveRecord::Base
  named_scope :has_moo,  :conditions => { :moo => true }
  named_scope :has_foo,  :conditions => { :foo => true }

  named_scope :has_moo_and_foo, lambda { has_moo.has_foo.scope(:find) } 
  #^^ we need scope(:find) at the end as return value can only be a Hash - how creat would this be if we can return a scope object as well??

end

# -> now this works:  
# Fu.has_moo_and_foo.all

#  Sweet!