From 6361512fe4ff93c1dc6156f52dee03f5f8cf0a2f Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Mon, 1 Sep 2014 12:32:03 +0300 Subject: [PATCH] Flip on locale setting --- app/controllers/application_controller.rb | 11 +++++++++++ app/views/layouts/_nav.html.erb | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 948c310..6cb183d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,6 +3,17 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception before_filter :configure_permitted_parameters, if: :devise_controller? + before_action :set_locale + + def default_url_options(options={}) + {locale: I18n.locale} + end + + private + + def set_locale + I18n.locale = params[:locale] || I18n.default_locale + end protected diff --git a/app/views/layouts/_nav.html.erb b/app/views/layouts/_nav.html.erb index b606851..9f4ca84 100644 --- a/app/views/layouts/_nav.html.erb +++ b/app/views/layouts/_nav.html.erb @@ -24,7 +24,11 @@ <% end %>
  • - English + <% if I18n.locale != :en %> + <%= link_to 'English', root_url(locale: 'en') %> + <% elsif I18n.locale != :bg %> + <%= link_to 'Български', root_url(locale: 'bg') %> + <% end %>