Skip to content

Instantly share code, notes, and snippets.

@clemens
Created April 22, 2015 15:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clemens/2b868e91fc37f3fde4cd to your computer and use it in GitHub Desktop.
Save clemens/2b868e91fc37f3fde4cd to your computer and use it in GitHub Desktop.
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