Extract save_cookies_from_locale comment-method

This commit is contained in:
Matt-Yorkley
2020-07-03 14:02:14 +02:00
parent 02549d1b0f
commit faa7c0a7c5

View File

@@ -9,11 +9,7 @@ class UserLocaleSetter
def call
save_locale_from_params
# After logging in, check if the user chose a locale before
if current_user_locale.nil? && cookies[:locale] && available_locale?(params_locale)
current_user&.update!(locale: params_locale)
end
save_locale_from_cookies
I18n.locale = valid_current_locale
end
@@ -47,6 +43,13 @@ class UserLocaleSetter
cookies[:locale] = params_locale
end
def save_locale_from_cookies
return unless current_user_locale.nil? && cookies[:locale] &&
available_locale?(params_locale)
current_user&.update!(locale: params_locale)
end
def available_locale?(locale)
self.class.available_locale?(locale)
end