Sha256: fc35378af5cc245a8ee926edee3fd214630e10767a54cf855f2d69559699be14

Contents?: true

Size: 897 Bytes

Versions: 5

Compression:

Stored size: 897 Bytes

Contents

module Guts
  # Main inherited controller class
  # @abstract
  class ApplicationController < ActionController::Base
    include SessionConcern
    include MultisiteConcern

    protect_from_forgery with: :exception
    before_action :current_user

    # Handles when user is not authorized from CanCanCan
    rescue_from CanCan::AccessDenied do |exception|
      # Redirects to login screen with error message
      redirect_to new_session_path, alert: exception.message
    end

    # Used by CanCanCan for getting the current abilities of the current user
    # @return [Class] the abilities for the current user
    def current_ability
      @current_ability ||= Guts::Ability.new current_user
    end

    protected

    # Gets the current user's record
    # @return [Object] the user object
    def current_user
      @current_user ||= User.find_by(id: session[:user_id])
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
guts-2.1.0 app/controllers/guts/application_controller.rb
guts-2.0.2 app/controllers/guts/application_controller.rb
guts-2.0.1 app/controllers/guts/application_controller.rb
guts-2.0.0 app/controllers/guts/application_controller.rb
guts-1.4.0 app/controllers/guts/application_controller.rb