Sha256: f2a9a118f2f4fc8f4acd7a320160ad0d2619ed56108fcbd8290713d8044feb02

Contents?: true

Size: 1.71 KB

Versions: 4

Compression:

Stored size: 1.71 KB

Contents

require 'cancan'
require 'state_machine'

module Pageflow
  class ApplicationController < ActionController::Base
    layout 'pageflow/application'

    before_filter do
      I18n.locale = current_user.try(:locale) || locale_from_accept_language_header || I18n.default_locale
    end

    # Prevent CSRF attacks by raising an exception.
    # For APIs, you may want to use :null_session instead.
    protect_from_forgery with: :exception

    include EditLocking

    rescue_from ActionController::UnknownFormat do
      render(status: 404, text: 'Not found')
    end

    rescue_from ActiveRecord::RecordNotFound do
      respond_to do |format|
        format.html { render :file => Rails.root.join('public/404.html'), :status => :not_found }
        format.any(:json, :css) { head :not_found }
      end
    end

    rescue_from CanCan::AccessDenied do |exception|
      respond_to do |format|
        format.html { redirect_to main_app.admin_root_path, :alert => t('pageflow.unauthorized') }
        format.any(:json, :css) { head :forbidden }
      end
    end

    rescue_from StateMachine::InvalidTransition do |exception|
      respond_to do |format|
        format.html { redirect_to main_app.admin_root_path, :alert => t('pageflow.invalid_transition') }
        format.json { head :bad_request }
      end
    end

    protected

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

    def after_sign_in_path_for(resource_or_scope)
      root_url(:protocol => 'http')
    end

    def after_sign_out_path_for(resource_or_scope)
      root_url(:protocol => 'http')
    end

    def locale_from_accept_language_header
      http_accept_language.compatible_language_from(I18n.available_locales)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pageflow-0.10.0 app/controllers/pageflow/application_controller.rb
pageflow-0.9.2 app/controllers/pageflow/application_controller.rb
pageflow-0.9.1 app/controllers/pageflow/application_controller.rb
pageflow-0.9.0 app/controllers/pageflow/application_controller.rb