Skip to content

Instantly share code, notes, and snippets.

@brandon-beacher
Created March 30, 2012 17:51
Show Gist options
  • Save brandon-beacher/2253352 to your computer and use it in GitHub Desktop.
Save brandon-beacher/2253352 to your computer and use it in GitHub Desktop.
class AgenciesController < ApplicationController
before_filter :require_user
def show
@agency = Agency.find(params[:id])
forbid unless current_user.admin_of_agency?(@agency)
end
end
class User < ActiveRecord::Base
has_many :administered_agencies, through: :agency_admins, source: :agency
has_many :agency_admins
def admin_of_agency?(agency)
system_admin? || administered_agencies.include?(agency)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment