Sha256: b5b1a41b812f10d57fca5847c6a36bab62647d0f8a52f8762b7d6edf302840b0

Contents?: true

Size: 830 Bytes

Versions: 7

Compression:

Stored size: 830 Bytes

Contents

class ApplicationController < ActionController::Base
  include TheRole::Controller

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

  protect_from_forgery
  before_filter :set_locale

  def access_denied
    flash[:error] = t('the_role.access_denied')
    redirect_to(:back)
  end

  private

  def set_locale
    locale = 'en'
    langs  = %w{ en ru es pl zh_CN }

    if params[:locale]
      lang = params[:locale]
      if langs.include? lang
        locale           = lang
        cookies[:locale] = lang
      end
    else
      if cookies[:locale]
        lang   = cookies[:locale]
        locale = lang if langs.include? lang
      end
    end

    I18n.locale = locale
    redirect_to(:back) if params[:locale]
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
the_role-2.5.4 spec/dummy_app/app/controllers/application_controller.rb
the_role-2.5.3 spec/dummy_app/app/controllers/application_controller.rb
the_role-2.5.2 spec/dummy_app/app/controllers/application_controller.rb
the_role-2.5.1 spec/dummy_app/app/controllers/application_controller.rb
the_role-2.5 spec/dummy_app/app/controllers/application_controller.rb
the_role-2.4 spec/dummy_app/app/controllers/application_controller.rb
the_role-2.3 spec/dummy_app/app/controllers/application_controller.rb