Sha256: 028e1f371a96bbfc3c9481e49182a1fa0f1efe8741b370898dbf955f0a11af4a

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

# -*- encoding : utf-8 -*-
module RademadeAdmin
  class AbstractController < ApplicationController

    include ::RademadeAdmin::UriHelper
    include ::RademadeAdmin::Breadcrumbs

    layout 'rademade_admin'

    before_action :init_user, :init_template_service, :require_login, :root_breadcrumbs, :menu
    
    attr_reader :current_user

    rescue_from ::CanCan::AccessDenied do |exception|
      redirect_to root_url, :alert => exception.message
    end

    protected

    def require_login
      redirect_to login_url unless admin_logged_in?
    end

    def init_user
      @current_user = RademadeAdmin.user_class.find(session[:user_id]) if session[:user_id].present?
    end

    def init_template_service
      @template_service = RademadeAdmin::TemplateService.new('rademade_admin')
    end

    def render_errors(errors)
      render :json => {
        :errors => errors,
        :message => 'Error occurred'
      }, :status => :unprocessable_entity
    end

    def admin_logged_in?
      @current_user.is_a? RademadeAdmin.user_class and @current_user.admin?
    end

    def current_ability
      @current_ability ||= (RademadeAdmin.ability_class || ::RademadeAdmin::Ability).new(@current_user)
    end

    def menu
      MenuCell.current_ability = current_ability
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rademade_admin-0.2.2 app/controllers/rademade_admin/abstract_controller.rb
rademade_admin-0.2.1 app/controllers/rademade_admin/abstract_controller.rb
rademade_admin-0.2.0 app/controllers/rademade_admin/abstract_controller.rb
rademade_admin-0.1.6 app/controllers/rademade_admin/abstract_controller.rb
rademade_admin-0.1.5 app/controllers/rademade_admin/abstract_controller.rb