Extract model to handle locales settings

This way we can simplify the view, particularly the form. However, we're
still adding some complexity to the form so inputs are inside labels and
so the collection is easier to style with CSS.
This commit is contained in:
Javi Martín
2024-04-10 03:38:00 +02:00
parent 2596b4e78b
commit 0c59c2dfb4
15 changed files with 99 additions and 47 deletions

View File

@@ -1,15 +1,27 @@
class Admin::LocalesController < Admin::BaseController
before_action :set_locales_settings
authorize_resource :locales_settings
def show
@enabled_locales = Setting.enabled_locales
@default_locale = Setting.default_locale
end
def update
Setting.transaction do
Setting["locales.default"] = params["default_locale"]
Setting["locales.enabled"] = [params["default_locale"], *params["enabled_locales"]].join(" ")
end
@locales_settings.update!(locales_settings_params)
redirect_to admin_locales_path, notice: t("admin.locales.update.notice")
end
private
def locales_settings_params
params.require(:setting_locales_settings).permit(allowed_params)
end
def allowed_params
[:default, enabled: []]
end
def set_locales_settings
@locales_settings = Setting::LocalesSettings.new
end
end