diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-04-08 02:30:50 +0200 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-04-08 02:30:50 +0200 |
commit | 4b621188adcd3e68272fc58db3cb5dfe51e71b38 (patch) | |
tree | 45df5941a51262e9ad1f316208ff4cde9c7732c5 /app/controllers/concerns | |
parent | a872f2f4c64f4a370fa1a92a28f9c07c1dd3b06d (diff) |
Fix #1165 - before_action was called before protect_from_forgery
Diffstat (limited to 'app/controllers/concerns')
-rw-r--r-- | app/controllers/concerns/localized.rb | 20 |
1 files changed, 16 insertions, 4 deletions
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 |