Extract method do update I18n contents
This way we can test it properly, which will be helpful when fixing bugs.
This commit is contained in:
@@ -7,24 +7,7 @@ class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomiz
|
||||
end
|
||||
|
||||
def update
|
||||
content_params.each do |content|
|
||||
values = content[:values].slice(*translation_params)
|
||||
|
||||
unless values.empty?
|
||||
values.each do |key, value|
|
||||
locale = key.split("_").last
|
||||
|
||||
if value == t(content[:id], locale: locale) || value.match(/translation missing/)
|
||||
next
|
||||
else
|
||||
text = I18nContent.find_or_create_by!(key: content[:id])
|
||||
Globalize.with_locale(locale) do
|
||||
text.update!(value: value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
I18nContent.update(content_params, enabled_translations)
|
||||
|
||||
redirect_to admin_site_customization_information_texts_path,
|
||||
notice: t("flash.actions.update.translation")
|
||||
@@ -48,12 +31,6 @@ class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomiz
|
||||
end
|
||||
end
|
||||
|
||||
def translation_params
|
||||
I18nContent.translated_attribute_names.product(enabled_translations).map do |attr_name, loc|
|
||||
I18nContent.localized_attr_name_for(attr_name, loc)
|
||||
end
|
||||
end
|
||||
|
||||
def enabled_translations
|
||||
params.fetch(:enabled_translations, {}).select { |_, v| v == "1" }.keys
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user