Skip to content

Instantly share code, notes, and snippets.

@stevepolitodesign
Last active May 18, 2021 18:17
Show Gist options
  • Save stevepolitodesign/d780529ac6db7de57354354bfb012190 to your computer and use it in GitHub Desktop.
Save stevepolitodesign/d780529ac6db7de57354354bfb012190 to your computer and use it in GitHub Desktop.
Authorize Teams with Pundit
# app/controllers/posts_controller.rb
def show
raise Pundit::NotAuthorizedError unless PostPolicy.new(current_team, @post).show?
end
# app/policies/post_policy.rb
class PostPolicy < ApplicationPolicy
# Rename attributes for clarity
attr_reader :team, :record
def initialize(team, record)
@team = team
@record = record
end
def show?
team.has_access_to_feature?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment