Skip to content

Instantly share code, notes, and snippets.

@dgilperez
Forked from ryanb/abilities.rb
Created August 6, 2014 14:34
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 dgilperez/85681f6db4e45804c1e4 to your computer and use it in GitHub Desktop.
Save dgilperez/85681f6db4e45804c1e4 to your computer and use it in GitHub Desktop.
module Abilities
def self.ability_for(user)
if user.admin?
AdminAbility.new(user)
else user
MemberAbility.new(user)
else
GuestAbility.new
end
end
class AdminAbility
include CanCan::Ability
def initialize(user)
# ...
end
end
class MemberAbility
include CanCan::Ability
def initialize(user)
# ...
end
end
class GuestAbility
include CanCan::Ability
def initialize(user)
# ...
end
end
# move classes into separate files as needed if they get too long
end
def current_ability
@current_ability ||= Abilities.ability_for(current_user)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment