From 7695a3ac5d70299de65cfe3315cffb3fc866fc0a Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Mon, 6 Apr 2015 16:29:23 -0300 Subject: [PATCH] Fixed locale setting by user for turbolinks and devise --- app/controllers/application_controller.rb | 18 ++++++++++++++---- app/views/layouts/application.html.erb | 2 +- spec/controllers/reading_groups_controller_spec.rb | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c5968d1..99396fc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,8 +10,22 @@ class ApplicationController < ActionController::Base before_filter :configure_permitted_parameters, if: :devise_controller? before_filter :set_locale + # This is necessary for correct devise routing with locales: https://github.com/plataformatec/devise/wiki/How-To:--Redirect-with-locale-after-authentication-failure + def self.default_url_options + merge_locale_to_options(super()) + end + + # This happens after the *_url *_path helpers + def default_url_options(options = {}) + self.class.merge_locale_to_options(options) + end + protected + def self.merge_locale_to_options(options) + { locale: I18n.locale }.merge options + end + # :nocov: def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up) << :name @@ -29,8 +43,4 @@ class ApplicationController < ActionController::Base 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/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index cc01a01..8724a5d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -78,7 +78,7 @@ diff --git a/spec/controllers/reading_groups_controller_spec.rb b/spec/controllers/reading_groups_controller_spec.rb index dfa6727..41ca25e 100644 --- a/spec/controllers/reading_groups_controller_spec.rb +++ b/spec/controllers/reading_groups_controller_spec.rb @@ -121,7 +121,7 @@ describe ReadingGroupsController, :type => :controller do delete :destroy, :id => @subject.id end - it { is_expected.to redirect_to new_user_session_path } + it { is_expected.to redirect_to new_user_session_url } end end -- libgit2 0.21.2