Skip to content

Instantly share code, notes, and snippets.

@buddhamagnet
Created May 23, 2012 10:05
Show Gist options
  • Save buddhamagnet/2774372 to your computer and use it in GitHub Desktop.
Save buddhamagnet/2774372 to your computer and use it in GitHub Desktop.
UNBOUND: SCOPES
scope :is_a, lambda { |role| joins(:roles).where("roles.name = ?", role) }
scope :subscribed_to, lambda { |book_id| joins(:subscriptions).where("subscriptions.book_id = ?", book_id) }
scope :authors, User.is_a("author")
scope :testers, User.is_a("tester")
scope :accountants, User.is_a("accountant")
scope :admins, User.is_a("admin")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment