Sha256: 1899c7cf68105e26382c272c119a8f55b36a5819dcc9e23468cdbd1f7c90d251

Contents?: true

Size: 1.78 KB

Versions: 26

Compression:

Stored size: 1.78 KB

Contents

class ApplicationController < ActionController::Base
  protect_from_forgery

  rescue_from CanCan::AccessDenied, :with => :render_403
  rescue_from ActiveRecord::RecordNotFound, :with => :render_404

  before_filter :set_locale
  
  private
  def render_403
    return if performed?
    if user_signed_in?
      respond_to do |format|
        format.html {render :template => 'page/403', :status => 403}
        format.mobile {render :template => 'page/403', :status => 403}
        format.xml {render :template => 'page/403', :status => 403}
        format.json
      end
    else
      respond_to do |format|
        format.html {redirect_to new_user_session_url}
        format.mobile {redirect_to new_user_session_url}
        format.xml {render :template => 'page/403', :status => 403}
        format.json
      end
    end
  end

  def render_404
    return if performed?
    respond_to do |format|
      format.html {render :template => 'page/404', :status => 404}
      format.mobile {render :template => 'page/404', :status => 404}
      format.xml {render :template => 'page/404', :status => 404}
      format.json
    end
  end

  def set_locale
    if params[:locale]
      unless I18n.available_locales.include?(params[:locale].to_s.intern)
        raise InvalidLocaleError
      end
    end
    if user_signed_in?
      locale = params[:locale] || session[:locale] || current_user.locale.try(:to_sym)
    else
      locale = params[:locale] || session[:locale]
    end
    if locale
      I18n.locale = @locale = session[:locale] = locale.to_sym
    else
      I18n.locale = @locale = session[:locale] = I18n.default_locale
    end
  rescue InvalidLocaleError
    @locale = I18n.default_locale
  end

  def access_denied
    raise CanCan::AccessDenied
  end
end

class InvalidLocaleError < StandardError
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
enju_inventory-0.1.11.pre8 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.1.11.pre7 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.1.11.pre6 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.1.11.pre5 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.1.11.pre4 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.1.11.pre2 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.1.11.pre spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.1.10 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.1.9 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.0.11 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.1.7 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.1.6 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.0.10 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.1.5 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.1.4 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.0.9 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.0.8 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.1.3 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.1.2 spec/dummy/app/controllers/application_controller.rb
enju_inventory-0.0.7 spec/dummy/app/controllers/application_controller.rb