Sha256: 8e528a2622c02b07e0d82e240245d5db82c3d34111dfaf17ec5783bc8c086c6b

Contents?: true

Size: 1.54 KB

Versions: 8

Compression:

Stored size: 1.54 KB

Contents

module Kadmin
  class ApplicationController < ActionController::Base
    layout 'kadmin/application'

    helper Kadmin::ApplicationHelper
    helper Kadmin::BootstrapHelper
    helper Kadmin::NavigationHelper
    helper Kadmin::PaginationHelper

    include Kadmin::Concerns::AuthorizedUser

    before_action :authorize
    before_action :set_navbar_links
    before_action :set_default_format

    # @!group Error Handling

    unless defined?(BetterErrors)
      rescue_from StandardError, with: :handle_error
      rescue_from ActiveRecord::RecordNotFound, with: :not_found
      rescue_from ActionController::ParameterMissing, with: :params_missing
    end

    def params_missing(error)
      handle_error(error, title: I18n.t('kadmin.errors.params_missing'), status: :bad_request)
    end

    def not_found(error)
      handle_error(error, title: I18n.t('kadmin.errors.not_found'), status: :not_found)
    end

    def handle_error(error, options = {})
      options = {
        title: error.try(:title) || error.class.name,
        message: error.message,
        status: :internal_server_error
      }.merge(options)
      render 'kadmin/error', status: options[:status], locals: options
    end

    # @!endgroup

    # @!group Helpers

    # Overload in the sub-controllers to set up the links in the layout
    def set_navbar_links
      @layout_navbar_links = []
    end
    protected :set_navbar_links

    def set_default_format
      params[:format] = 'html' if params[:format].blank?
    end
    protected :set_default_format

    # @!endgroup
  end
end

Version data entries

8 entries across 6 versions & 1 rubygems

Version Path
kadmin-0.2.6 app/controllers/kadmin/application_controller.rb
kadmin-0.2.3 app/controllers/kadmin/application_controller.rb
kadmin-0.2.2 app/controllers/kadmin/application_controller.rb
kadmin-0.1.7 app/controllers/kadmin/application_controller.rb
kadmin-0.1.6 app/controllers/rails_admin/application_controller.rb
kadmin-0.1.6 app/controllers/kadmin/application_controller.rb
kadmin-0.1.4 app/controllers/kadmin/application_controller.rb
kadmin-0.1.4 app/controllers/rails_admin/application_controller.rb