Created
May 6, 2015 12:55
-
-
Save knoxknox/f4e5e7836db73e51a898 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
# controllers/application_controller.rb | |
class ApplicationController | |
# @override | |
def current_ability | |
@current_ability ||= Ability::Factory.build(user) | |
end | |
end | |
# ability/factory.rb | |
class Ability::Factory | |
def self.build(user) | |
case user.role | |
when :user then Ability::User.new(user) | |
when :admin then Ability::Admin.new(user) | |
when :editor then Ability::Editor.new(user) | |
end | |
end | |
end | |
# ability/editor.rb | |
class Ability::Editor < Ability | |
def initialize(user) | |
can :view, Report, last_modifier_id: user.id | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment