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