Sha256: 726b694c6f6e8b59e69df70df4cfe5dce6345f666c5fadbc3cf848beef6090eb

Contents?: true

Size: 947 Bytes

Versions: 4

Compression:

Stored size: 947 Bytes

Contents

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  before_filter :set_locale

  private

  def extract_locale_from_accept_language_header
    browser_locale   = request.env['HTTP_ACCEPT_LANGUAGE'].try(:scan, /^[a-z]{2}/).try(:first).try(:to_sym)
    session[:locale] = browser_locale if I18n.available_locales.include? browser_locale
  end

  def set_locale
    extract_locale_from_accept_language_header if session[:locale].blank?
    session[:locale] = I18n.default_locale if session[:locale].blank?
    session[:locale] = params[:locale] if params[:locale]
    I18n.locale = session[:locale]
    Rails.application.routes.default_url_options[:locale]= I18n.locale 
  end

  # prepare variable for the views
  def set_installed_shops
    @installed_shops = session[:installed_shops]
  end


end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
versacommerce_app-1.0.28 lib/generators/versacommerce_app/templates/app/controllers/application_controller.rb
versacommerce_app-1.0.27 lib/generators/versacommerce_app/templates/app/controllers/application_controller.rb
versacommerce_app-1.0.26 lib/generators/versacommerce_app/templates/app/controllers/application_controller.rb
versacommerce_app-1.0.25 lib/generators/versacommerce_app/templates/app/controllers/application_controller.rb