Skip to content

Instantly share code, notes, and snippets.

@donpdonp
Created September 22, 2010 17:24
Show Gist options
  • Save donpdonp/592115 to your computer and use it in GitHub Desktop.
Save donpdonp/592115 to your computer and use it in GitHub Desktop.
## From the cancan home page
class Ability
include CanCan::Ability
def initialize(user)
if user.admin?
can :manage, :all
else
can :read, :all
end
end
end
## database-driven
class Ability
include CanCan::Ability
def initialize(user)
permission = Permission.find_by_level(user.level)
permission.allowed_actons do |action|
can action.to_sym, :all
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment