Module: PunditCustomErrors::Authorization
- Included in:
- Pundit
- Defined in:
- lib/pundit_custom_errors/authorization.rb
Overview
Module created to override Pundit’s ‘authorize’ function. It enables Pundit to use the ‘error_message’ attribute (if existent) inside a Policy object, displaying the given error message instead of a default error message.
Instance Method Summary collapse
Instance Method Details
#authorize(record, query = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/pundit_custom_errors/authorization.rb', line 6 def (record, query = nil) @_pundit_policy_authorized = true query ||= params[:action].to_s + '?' policy = policy(record) unless policy.public_send(query) fail generate_error_for(policy, query, record) end true end |