From 4b621188adcd3e68272fc58db3cb5dfe51e71b38 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 8 Apr 2017 02:30:50 +0200 Subject: Fix #1165 - before_action was called before protect_from_forgery --- app/controllers/concerns/localized.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'app/controllers/concerns/localized.rb') diff --git a/app/controllers/concerns/localized.rb b/app/controllers/concerns/localized.rb index b6f868090..6528ce45e 100644 --- a/app/controllers/concerns/localized.rb +++ b/app/controllers/concerns/localized.rb @@ -4,13 +4,25 @@ module Localized extend ActiveSupport::Concern included do - before_action :set_locale + around_action :set_locale end + private + def set_locale - I18n.locale = current_user.try(:locale) || default_locale - rescue I18n::InvalidLocale - I18n.locale = default_locale + locale = default_locale + + if user_signed_in? + begin + locale = current_user.try(:locale) || default_locale + rescue I18n::InvalidLocale + locale = default_locale + end + end + + I18n.with_locale(locale) do + yield + end end def default_locale -- cgit