Sha256: fb109d1848af4ff2029f9d93cc0370fbfa162d7113e79be92d1b09e499065754

Contents?: true

Size: 1.88 KB

Versions: 15

Compression:

Stored size: 1.88 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

  enju_resource_merge
  
  private
  def render_403
    return if performed?
    if user_signed_in?
      respond_to do |format|
        format.html {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.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.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

  def get_series_statement
    @series_statement = SeriesStatement.find(params[:series_statement_id]) if params[:series_statement_id]
  end

  def get_patron
    @patron = Patron.find(params[:patron_id]) if params[:patron_id]
    authorize! :show, @patron if @patron
  end
end

class InvalidLocaleError < StandardError
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
enju_resource_merge-0.1.0.pre7 spec/dummy/app/controllers/application_controller.rb
enju_resource_merge-0.1.0.pre6 spec/dummy/app/controllers/application_controller.rb
enju_resource_merge-0.1.0.pre5 spec/dummy/app/controllers/application_controller.rb
enju_resource_merge-0.1.0.pre4 spec/dummy/app/controllers/application_controller.rb
enju_resource_merge-0.1.0.pre3 spec/dummy/app/controllers/application_controller.rb
enju_resource_merge-0.1.0.pre2 spec/dummy/app/controllers/application_controller.rb
enju_resource_merge-0.1.0.pre spec/dummy/app/controllers/application_controller.rb
enju_resource_merge-0.0.17 spec/dummy/app/controllers/application_controller.rb
enju_resource_merge-0.0.16 spec/dummy/app/controllers/application_controller.rb
enju_resource_merge-0.0.15 spec/dummy/app/controllers/application_controller.rb
enju_resource_merge-0.0.14 spec/dummy/app/controllers/application_controller.rb
enju_resource_merge-0.0.13 spec/dummy/app/controllers/application_controller.rb
enju_resource_merge-0.0.12 spec/dummy/app/controllers/application_controller.rb
enju_resource_merge-0.0.11 spec/dummy/app/controllers/application_controller.rb
enju_resource_merge-0.0.10 spec/dummy/app/controllers/application_controller.rb