Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # this is an AR model class
- named_scope :privates, :conditions => { :public => false }
- named_scope :named_like, lambda { |name| { :conditions => "name LIKE '#{name}%'" }}
- # we want to concatenate named_scopes at later points in code
- def self.by_privacy_and_name(privates = false, name = nil)
- # we want a named_scope to concatenate other namescopes afterwards
- gs = if privates
- self.privates # with named_scopes everything runs fine
- else
- self.all # here we won't get a NamedScope, instead it'll be an Array
- end
- if name
- gs.named_like name # this blows with Array returned by AR.all
- else
- gs
- end
- end
Add Comment
Please, Sign In to add comment