Created
April 22, 2015 15:11
-
-
Save clemens/2b868e91fc37f3fde4cd to your computer and use it in GitHub Desktop.
This file contains hidden or 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 AgencyVisitPolicy | |
def initialize(user) | |
@user = user | |
end | |
def to_proc | |
Proc.new { |visit| visit.agency_id.in?([@user.agency_id, nil]) } | |
end | |
end | |
class Ability | |
include CanCan::Ability | |
def initialize(user) | |
if user.agency? | |
can :manage, Visit do |visit| | |
visit.agency_id.in?([user.agency_id, nil]) | |
end | |
# this does the same: | |
can :manage, Visit, &AgencyVisitPolicy.new(user) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment