Created
March 2, 2010 16:45
-
-
Save stevegraham/319658 to your computer and use it in GitHub Desktop.
This file contains 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) | |
return if user.nil? | |
# Collect rights from roles | |
authorizations = HashWithIndifferentAccess.new [] | |
user.roles.each do |role| | |
role.resource_rights.each { |resource,actions| authorizations[resource] |= actions } | |
end | |
# Grant rights | |
authorizations.each { |resource,actions| can actions, resource.to_s.classify.constantize } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment