Created
December 7, 2015 06:23
-
-
Save ishouvik/24c225426107536578bf to your computer and use it in GitHub Desktop.
Default Ability Class with Devise, Rolify and Cancan
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) | |
user ||= User.new # guest user (not logged in) | |
if user.has_role? :admin | |
can :manage, :all | |
elsif user.has_role? :user | |
can :read, :all | |
can :manage, :all, owner: user | |
else | |
can :read, :all | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment