Sha256: 760aaad9dbd84718c28cb35d49887d42d6e61c0fa1b209052188309171cd205d
Contents?: true
Size: 823 Bytes
Versions: 15
Compression:
Stored size: 823 Bytes
Contents
module Controller module PunditAuthorizationFailureHandlingConcern extend ActiveSupport::Concern included do rescue_from Pundit::NotAuthorizedError, with: :not_authorized end private def not_authorized(exception) resource_name = exception.record.respond_to?(:model_name) ? exception.record.model_name.human : exception.record collection_name = exception.record.respond_to?(:model_name) ? exception.record.model_name.human(count: :other) : exception.record flash[:error] = I18n.t("pundit.not_authorized.#{action_name}", collection_name: collection_name,resource_name: resource_name) respond_to do |format| format.html { redirect_to main_app.root_path } format.json { render json: { error: 'not authorized' }, status: 403 } end end end end
Version data entries
15 entries across 15 versions & 1 rubygems