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.33 app/controllers/tenon/base_controller.rb
tenon-1.0.32 app/controllers/tenon/base_controller.rb
tenon-1.0.31 app/controllers/tenon/base_controller.rb
tenon-1.0.30 app/controllers/tenon/base_controller.rb
tenon-1.0.29 app/controllers/tenon/base_controller.rb
tenon-1.0.28 app/controllers/tenon/base_controller.rb
tenon-1.0.27 app/controllers/tenon/base_controller.rb
tenon-1.0.26 app/controllers/tenon/base_controller.rb
tenon-1.0.25 app/controllers/tenon/base_controller.rb
tenon-1.0.24 app/controllers/tenon/base_controller.rb
tenon-1.0.23 app/controllers/tenon/base_controller.rb
tenon-1.0.22 app/controllers/tenon/base_controller.rb
tenon-1.0.21 app/controllers/tenon/base_controller.rb
tenon-1.0.20 app/controllers/tenon/base_controller.rb
tenon-1.0.19 app/controllers/tenon/base_controller.rb
tenon-1.0.18 app/controllers/tenon/base_controller.rb
tenon-1.0.17 app/controllers/tenon/base_controller.rb
tenon-1.0.16 app/controllers/tenon/base_controller.rb
tenon-1.0.15 app/controllers/tenon/base_controller.rb
tenon-1.0.14 app/controllers/tenon/base_controller.rb