Guest User

Untitled

a guest
Apr 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. # this is an AR model class
  2. named_scope :privates, :conditions => { :public => false }
  3. named_scope :named_like, lambda { |name| { :conditions => "name LIKE '#{name}%'" }}
  4.  
  5. # we want to concatenate named_scopes at later points in code
  6. def self.by_privacy_and_name(privates = false, name = nil)
  7. # we want a named_scope to concatenate other namescopes afterwards
  8. gs = if privates
  9. self.privates # with named_scopes everything runs fine
  10. else
  11. self.all # here we won't get a NamedScope, instead it'll be an Array
  12. end
  13. if name
  14. gs.named_like name # this blows with Array returned by AR.all
  15. else
  16. gs
  17. end
  18. end
Add Comment
Please, Sign In to add comment