Last active
August 29, 2015 14:03
-
-
Save beck03076/93af7adaf8c8d0c8f376 to your computer and use it in GitHub Desktop.
ability
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
| class Ability | |
| include CanCan::Ability | |
| def initialize(user) | |
| user.permissions.each do |permission| | |
| if permission.subject_id.nil? | |
| if permission.subject_class == "All" | |
| can permission.action.to_sym, :all | |
| else | |
| can permission.action.to_sym, permission.subject_class.constantize | |
| end | |
| else | |
| can permission.action.to_sym, permission.subject_class.constantize, :id => user.id | |
| end | |
| end | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
examples: permission: {subject_class: "Institution", action: "read"}