class Pundit::NotAuthorizedError

Error that will be raised when authorization has failed

def initialize(options = {})

Options Hash: (**options)
  • :policy (Class) -- The class of policy that was used for the check.
  • :record (Object) -- The object that was being checked with the policy.
  • :query (Symbol) -- The name of the policy method that was checked.
  • :message (String) -- Optional custom error message. Will default to a generalized message.

Parameters:
  • options (Hash) -- The error options.
  • message (String) -- A simple error message string.

Overloads:
  • initialize(options)
  • initialize(message)
def initialize(options = {})
  if options.is_a? String
    message = options
  else
    @query  = options[:query]
    @record = options[:record]
    @policy = options[:policy]
    message = options.fetch(:message) do
      record_name = record.is_a?(Class) ? record.to_s : "this #{record.class}"
      "not allowed to #{policy.class}##{query} #{record_name}"
    end
  end
  super(message)
end