From a397678ef0c51ee6d8a99b50c2329ec8f5556b36 Mon Sep 17 00:00:00 2001 From: Paolo Dona Date: Mon, 22 Apr 2013 06:26:50 +0100 Subject: [PATCH 1/3] use prepend_before_filter instead of append_before_filter so other filters have access to the locale set --- lib/rails_locale_detection/controller_methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rails_locale_detection/controller_methods.rb b/lib/rails_locale_detection/controller_methods.rb index 28ef7dd..a4cfeb6 100644 --- a/lib/rails_locale_detection/controller_methods.rb +++ b/lib/rails_locale_detection/controller_methods.rb @@ -9,7 +9,7 @@ module ControllerMethods module ClassMethods def detect_locale - append_before_filter LocaleDetector + prepend_before_filter LocaleDetector end end From cf2c2b7a23d59f63ca8ecdb0be378a3a0830ee65 Mon Sep 17 00:00:00 2001 From: Paolo Dona Date: Mon, 22 Apr 2013 06:26:50 +0100 Subject: [PATCH 2/3] use prepend_before_filter instead of append_before_filter so other filters have access to the locale set --- lib/rails_locale_detection/controller_methods.rb | 2 +- spec/support/mocks.rb | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/rails_locale_detection/controller_methods.rb b/lib/rails_locale_detection/controller_methods.rb index 28ef7dd..a4cfeb6 100644 --- a/lib/rails_locale_detection/controller_methods.rb +++ b/lib/rails_locale_detection/controller_methods.rb @@ -9,7 +9,7 @@ module ControllerMethods module ClassMethods def detect_locale - append_before_filter LocaleDetector + prepend_before_filter LocaleDetector end end diff --git a/spec/support/mocks.rb b/spec/support/mocks.rb index 5aaaf85..1e13a93 100644 --- a/spec/support/mocks.rb +++ b/spec/support/mocks.rb @@ -6,18 +6,18 @@ class MockRequest def initialize @env = {'HTTP_ACCEPT_LANGUAGE' => ''} end - + def host "localhost" end - + def ssl? false end - + def cookies {} - end + end end class MockUser @@ -56,6 +56,11 @@ def self.append_before_filter(*args) @before_filters << args end + def self.prepend_before_filter(*args) + @before_filters ||= [] + @before_filters << args + end + include RailsLocaleDetection::ControllerMethods -end \ No newline at end of file +end From 0ec1fda9431356d68ea0d94a66e1e947bf0318e7 Mon Sep 17 00:00:00 2001 From: Paolo Dona Date: Sat, 27 Jul 2013 17:17:30 +0100 Subject: [PATCH 3/3] use controller's private method cookies (for rails4) --- lib/rails_locale_detection/locale_detector.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/rails_locale_detection/locale_detector.rb b/lib/rails_locale_detection/locale_detector.rb index 8d28ee7..e1ec269 100644 --- a/lib/rails_locale_detection/locale_detector.rb +++ b/lib/rails_locale_detection/locale_detector.rb @@ -2,21 +2,25 @@ module RailsLocaleDetection class LocaleDetector include DetectionMethods include LocaleAccessors - + attr_reader :controller - - delegate :cookies, :params, :request, :default_url_options, :user_locale, :to => :controller - + + delegate :params, :request, :default_url_options, :user_locale, :to => :controller + def initialize(controller = nil) @controller = controller end - + def locale_key RailsLocaleDetection.locale_key end - + + def cookies + @controller.send(:cookies) + end + def self.before(controller) new(controller).set_locale end end -end \ No newline at end of file +end