Sha256: 994d446243d721e169f6c7a7bc660e962716e5241e8474231773711f73e23456

Contents?: true

Size: 1.17 KB

Versions: 34

Compression:

Stored size: 1.17 KB

Contents

module Tenon
  class BaseController < ApplicationController
    layout :layout_for_resource

    before_filter :set_title
    before_filter :require_admin, unless: :devise_controller?

    rescue_from CanCan::AccessDenied do |exception|
      flash[:warning] = 'You are not authorized to access that page.'
      redirect_to '/tenon'
    end

    private

    def layout_for_resource
      if devise_controller?
        'tenon/login'
      else
        'tenon/application'
      end
    end

    def set_title
      case params[:action]
      when 'new', 'create'
        @page_title = "New #{params[:controller].gsub('tenon/', '').singularize.humanize}".titleize
      when 'edit', 'update'
        @page_title = "Edit #{params[:controller].gsub('tenon/', '').singularize.humanize}".titleize
      else
        @page_title = params[:controller].gsub('tenon/', '').humanize.titleize
      end
      @page_title = 'Tenon' if params[:controller].gsub('tenon/', '') == 'index'
    end

    def require_admin
      unless current_user && current_user.staff?
        flash[:warning] = "You're not authorized for that." if current_user
        redirect_to new_user_session_path
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
tenon-1.0.13 app/controllers/tenon/base_controller.rb
tenon-1.0.12 app/controllers/tenon/base_controller.rb
tenon-1.0.11 app/controllers/tenon/base_controller.rb
tenon-1.0.10 app/controllers/tenon/base_controller.rb
tenon-1.0.9 app/controllers/tenon/base_controller.rb
tenon-1.0.8 app/controllers/tenon/base_controller.rb
tenon-1.0.7 app/controllers/tenon/base_controller.rb
tenon-1.0.6 app/controllers/tenon/base_controller.rb
tenon-1.0.5 app/controllers/tenon/base_controller.rb
tenon-1.0.4 app/controllers/tenon/base_controller.rb
tenon-1.0.3 app/controllers/tenon/base_controller.rb
tenon-1.0.2 app/controllers/tenon/base_controller.rb
tenon-1.0.1 app/controllers/tenon/base_controller.rb
tenon-1.0 app/controllers/tenon/base_controller.rb