Sha256: ebfc345d7b934f29c609ac91e179207750b47a629c43403a89d7c55259091fcf

Contents?: true

Size: 1.17 KB

Versions: 45

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 root_path
    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

45 entries across 45 versions & 1 rubygems

Version Path
tenon-1.1.4 app/controllers/tenon/base_controller.rb
tenon-1.1.3 app/controllers/tenon/base_controller.rb
tenon-1.1.2 app/controllers/tenon/base_controller.rb
tenon-1.1.1 app/controllers/tenon/base_controller.rb
tenon-1.0.76 app/controllers/tenon/base_controller.rb
tenon-1.0.75 app/controllers/tenon/base_controller.rb
tenon-1.0.74 app/controllers/tenon/base_controller.rb
tenon-1.0.73 app/controllers/tenon/base_controller.rb
tenon-1.0.72 app/controllers/tenon/base_controller.rb
tenon-1.0.71 app/controllers/tenon/base_controller.rb
tenon-1.0.70 app/controllers/tenon/base_controller.rb
tenon-1.0.69 app/controllers/tenon/base_controller.rb
tenon-1.0.68 app/controllers/tenon/base_controller.rb
tenon-1.0.67 app/controllers/tenon/base_controller.rb
tenon-1.0.66 app/controllers/tenon/base_controller.rb
tenon-1.0.65 app/controllers/tenon/base_controller.rb
tenon-1.0.64 app/controllers/tenon/base_controller.rb
tenon-1.0.63 app/controllers/tenon/base_controller.rb
tenon-1.0.62 app/controllers/tenon/base_controller.rb
tenon-1.0.61 app/controllers/tenon/base_controller.rb