From fd1d1b353ac1a476985ed67fae3cece636d84151 Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Tue, 24 Mar 2015 13:35:29 -0300 Subject: [PATCH] Language can be set by the route --- app/controllers/application_controller.rb | 15 ++++++++++++--- app/controllers/concerns/ownership_authentication.rb | 4 ++-- app/views/layouts/application.html.erb | 23 ++++++++++++++++++++++- config/routes.rb | 68 ++++++++++++++++++++++++++++++++++++-------------------------------- features/compound_metric_configuration/create.feature | 1 + features/homepage.feature | 9 ++++++++- features/step_definitions/compound_metric_configuration_steps.rb | 4 ++-- features/step_definitions/kalibro_configuration_steps.rb | 6 +++--- features/step_definitions/kalibro_range_steps.rb | 8 ++++---- features/step_definitions/metric_configuration_steps.rb | 8 ++++---- features/step_definitions/project_steps.rb | 6 +++--- features/step_definitions/reading_group_steps.rb | 8 ++++---- features/step_definitions/reading_steps.rb | 6 +++--- features/step_definitions/repository_steps.rb | 6 +++--- spec/controllers/base_metric_configurations_controller_spec.rb | 2 +- spec/controllers/compound_metric_configurations_controller_spec.rb | 8 ++++---- spec/controllers/home_controller_spec.rb | 4 ++++ spec/controllers/kalibro_configurations_controller_spec.rb | 10 +++++----- spec/controllers/kalibro_ranges_controller_spec.rb | 20 ++++++++++---------- spec/controllers/metric_configurations_controller_spec.rb | 12 ++++++------ spec/controllers/repositories_controller_spec.rb | 2 +- spec/routing/home_routing_spec.rb | 2 ++ spec/routing/project_routing_spec.rb | 3 +++ 23 files changed, 143 insertions(+), 92 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d53225a..c5968d1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -19,9 +19,18 @@ class ApplicationController < ActionController::Base end def set_locale - compatible_locale = http_accept_language.compatible_language_from(I18n.available_locales) - unless compatible_locale.nil? - I18n.locale = compatible_locale + unless params[:locale].nil? + I18n.locale = params[:locale] + else + compatible_locale = http_accept_language.compatible_language_from(I18n.available_locales) + unless compatible_locale.nil? + I18n.locale = compatible_locale + end end end + + # This happens after the *_url *_path helpers + def default_url_options(options = {}) + { locale: I18n.locale == I18n.default_locale ? nil : I18n.locale }.merge options + end end diff --git a/app/controllers/concerns/ownership_authentication.rb b/app/controllers/concerns/ownership_authentication.rb index 9c8f897..cdb1db0 100644 --- a/app/controllers/concerns/ownership_authentication.rb +++ b/app/controllers/concerns/ownership_authentication.rb @@ -65,7 +65,7 @@ module OwnershipAuthentication def check_reading_group_ownership(id) if current_user.reading_group_ownerships.find_by_reading_group_id(id).nil? respond_to do |format| - format.html { redirect_to reading_group_url(id), notice: "You're not allowed to do this operation" } + format.html { redirect_to reading_group_url(id: id), notice: "You're not allowed to do this operation" } format.json { head :no_content } end end @@ -76,7 +76,7 @@ module OwnershipAuthentication def check_kalibro_configuration_ownership(id) if current_user.kalibro_configuration_ownerships.find_by_kalibro_configuration_id(id).nil? respond_to do |format| - format.html { redirect_to kalibro_configurations_url(id), notice: "You're not allowed to do this operation" } + format.html { redirect_to kalibro_configurations_url(id: id), notice: "You're not allowed to do this operation" } format.json { head :no_content } end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 82737de..21b6dd2 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -63,7 +63,7 @@
  • <%= link_to KalibroConfiguration.model_name.human, kalibro_configurations_path %>
  • <%= link_to ReadingGroup.model_name.human, reading_groups_path %>
  • -