Skip to content

Instantly share code, notes, and snippets.

@Intrepidd
Created April 17, 2012 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Intrepidd/2409377 to your computer and use it in GitHub Desktop.
Save Intrepidd/2409377 to your computer and use it in GitHub Desktop.
Demo of my gem rails-canhaz
user = User.find(42)
article = Article.find(1337)
user.can?(:read, article) # Can the user read this article? false for now
user.can(:read, article) # Ok, so the user can read this article
user.can(:edit, article) # He can edit it as well
user.can?(:read, article) # Will be true
user.objects_with_permission(Article, :read) # Will return all the articles w/ read permissions for this user
artice.subjects_with_permission(User, :read) # Will return all the users hat are able to read this article
#You can also remove permissions
user.cannot(:read, article)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment