Sha256: b23e5d557381fa3c83999ef7b15bdd98e7a93b2c8bd5748f0cf350e3847378f8

Contents?: true

Size: 1.65 KB

Versions: 10

Compression:

Stored size: 1.65 KB

Contents

module Gaku
  class CoreController < ActionController::Base
    protect_from_forgery
    # check_authorization

    rescue_from CanCan::AccessDenied do |exception|
      session[:previous_url] = request.fullpath unless request.fullpath =~ /\/users/
      redirect_to root_url, alert: exception.message
    end

    before_filter :set_locale
    before_filter :users_check

    # def user_for_paper_trail
    #   user_signed_in? ? current_user : 'Public user'  # or whatever
    # end

    protected

    def get_resource_name(object)
      object.class.to_s.underscore.split('/')[1].gsub('_', '-')
    end

    def get_class(object)
      object.class.to_s.underscore.dasherize.split('/').last
    end

    private

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

    def set_locale
      if current_user && params[:locale]
        I18n.locale = params[:locale]
        Carmen.i18n_backend.locale = I18n.locale
        current_user.settings[:locale] = params[:locale]
        notice = "Language is set to #{t('languages.' + current_user.locale)}"
        flash[:notice] = notice if current_user.save
      elsif current_user
        I18n.locale = current_user.settings[:locale]
        Carmen.i18n_backend.locale = I18n.locale
      else
        Carmen.i18n_backend.locale = I18n.default_locale
        I18n.default_locale
      end
    end

    def users_check
      redirect_to set_up_admin_account_path if User.count == 0
    end

    def extract_locale_from_accept_language_header
      request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
    end

    def after_sign_out_path_for(_resource_or_scope)
      root_path
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
gaku_core-0.3.0 app/controllers/gaku/core_controller.rb
gaku_core-0.3.0.pre.4 app/controllers/gaku/core_controller.rb
gaku_core-0.3.0.pre.3 app/controllers/gaku/core_controller.rb
gaku_core-0.3.0.pre.2 app/controllers/gaku/core_controller.rb
gaku_core-0.3.0.pre.1 app/controllers/gaku/core_controller.rb
gaku_core-0.3.0.pre.0 app/controllers/gaku/core_controller.rb
gaku-0.2.4 core/app/controllers/gaku/core_controller.rb
gaku_core-0.2.4 app/controllers/gaku/core_controller.rb
gaku-0.2.3 core/app/controllers/gaku/core_controller.rb
gaku_core-0.2.3 app/controllers/gaku/core_controller.rb