Sha256: 87b05ed91419435982fe769d3f48408eaaf7abfc958d0f6b5ce1f800ff8cb5b0
Contents?: true
Size: 912 Bytes
Versions: 22
Compression:
Stored size: 912 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 after_authorization_failure_path } format.json { render json: { error: 'not authorized' }, status: 403 } end end def after_authorization_failure_path main_app.root_path end end end
Version data entries
22 entries across 22 versions & 1 rubygems