From 41d463b3572a628f0c505e0fefff19f1be9e3609 Mon Sep 17 00:00:00 2001 From: elijah Date: Sat, 16 Jan 2016 14:51:42 -0800 Subject: retain locale in URL when logging in and signing up, and ajax actions in general. --- app/assets/javascripts/users.js | 14 ++++++++++++-- app/controllers/application_controller.rb | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/users.js b/app/assets/javascripts/users.js index 5217942..70d78fd 100644 --- a/app/assets/javascripts/users.js +++ b/app/assets/javascripts/users.js @@ -122,11 +122,21 @@ }; srp.loggedIn = function() { - return window.location = '/'; + return srp.localeRedirect('/'); }; srp.updated = function() { - return window.location = '/users/' + srp.session.id(); + return srp.localeRedirect('/users/' + srp.session.id()); + }; + + // redirect, while preserving locale if set by url path. + srp.localeRedirect = function(path) { + var localeMatch = window.location.pathname.match(/^(\/[a-z]{2})\//) + if (localeMatch) { + return window.location = localeMatch[1] + path; + } else { + return window.location = path; + } }; // diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a4cbfb5..079dc18 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -104,6 +104,6 @@ class ApplicationController < ActionController::Base # For some requests, we ignore locale determination. # def request_may_have_locale?(request) - request.method == "GET" && request.format == 'text/html' && request.path !~ NON_LOCALE_PATHS + request.path !~ NON_LOCALE_PATHS end end -- cgit v1.2.3