Skip to content

Instantly share code, notes, and snippets.

@pedrosmmoreira
Created February 17, 2017 11:23
Show Gist options
  • Save pedrosmmoreira/c93c4786fc5c24d209dedd25bad72f8b to your computer and use it in GitHub Desktop.
Save pedrosmmoreira/c93c4786fc5c24d209dedd25bad72f8b to your computer and use it in GitHub Desktop.
class FoosController < ApplicationController
include Pundit
#...
# record policy
def set_record_policy
policy(PolicyContext.new(record, current_user)
end
# scope policy
def set_policy_scope
policy_scope(PolicyContext.new(RecordClassName, current_user))
end
# authorizing controller action
def authorize_action
authorize PolicyContext.new(record, user), "#{action_name}?"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment