Skip to content

Instantly share code, notes, and snippets.

@ishouvik
Created December 7, 2015 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishouvik/24c225426107536578bf to your computer and use it in GitHub Desktop.
Save ishouvik/24c225426107536578bf to your computer and use it in GitHub Desktop.
Default Ability Class with Devise, Rolify and Cancan
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