Created
April 17, 2012 22:04
-
-
Save Intrepidd/2409377 to your computer and use it in GitHub Desktop.
Demo of my gem rails-canhaz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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