Class: Kadmin::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Concerns::AuthorizedUser
Defined in:
app/controllers/kadmin/application_controller.rb

Direct Known Subclasses

AuthController, DashController

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::AuthorizedUser

#authorize, #authorized_user, #current_user

Class Method Details



23
24
25
# File 'app/controllers/kadmin/application_controller.rb', line 23

def navbar_section
  return @navbar_section ||= self
end


19
20
21
# File 'app/controllers/kadmin/application_controller.rb', line 19

def navbar_section=(id)
  @navbar_section = id.to_s.freeze
end

Instance Method Details

#handle_error(error, options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'app/controllers/kadmin/application_controller.rb', line 49

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

#handle_unexpected_error(error) ⇒ Object



44
45
46
47
# File 'app/controllers/kadmin/application_controller.rb', line 44

def handle_unexpected_error(error)
  Rails.logger.error(error)
  handle_error(error, title: I18n.t('kadmin.errors.unexpected'), message: I18n.t('kadmin.errors.unexpected_message'))
end

#not_found(error) ⇒ Object



40
41
42
# File 'app/controllers/kadmin/application_controller.rb', line 40

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

#params_missing(error) ⇒ Object



36
37
38
# File 'app/controllers/kadmin/application_controller.rb', line 36

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