Sha256: f0e5a2434b27c6c9c5538c6c9c37ad447dbf6a7d7713b2912c4931f2729d9582

Contents?: true

Size: 761 Bytes

Versions: 7

Compression:

Stored size: 761 Bytes

Contents

# frozen_string_literal: true

module ErrorHandlers
  extend ActiveSupport::Concern

  included do
    rescue_from ActiveRecord::RecordInvalid, with: :render_not_found
    rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
    # rescue_from ActionController::RoutingError, with: :render_not_found
    rescue_from ActionView::MissingTemplate do
      render plain: '404 Not found', status: :not_found
    end
    # Pundit Authorization
    rescue_from Pundit::NotAuthorizedError, with: :not_authorized
  end

  private

  def not_authorized
    flash[:alert] = 'You are not authorized to access this page.'
    redirect_to(request.referer || root_path)
  end

  def render_not_found
    render template: 'errors/404', status: :not_found
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kowl-0.0.7 lib/kowl/templates/app/controllers/concerns/auth/error_handlers.rb
kowl-0.0.6 lib/kowl/templates/app/controllers/concerns/auth/error_handlers.rb
kowl-0.0.5 lib/kowl/templates/app/controllers/concerns/auth/error_handlers.rb
kowl-0.0.4 lib/kowl/templates/app/controllers/concerns/auth/error_handlers.rb
kowl-0.0.3 lib/kowl/templates/app/controllers/concerns/auth/error_handlers.rb
kowl-0.0.2 lib/kowl/templates/app/controllers/concerns/auth/error_handlers.rb
kowl-0.0.1 lib/kowl/templates/app/controllers/concerns/auth/error_handlers.rb