Files
grecia/app/models/setting/locales_settings.rb
Javi Martín 0c59c2dfb4 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.
2024-06-05 16:10:56 +02:00

24 lines
554 B
Ruby

class Setting
class LocalesSettings
include ActiveModel::Model
include ActiveModel::Attributes
attribute :enabled, array: true, default: -> { Setting.enabled_locales }
attribute :default, default: -> { Setting.default_locale }
def persisted?
true
end
def update(attributes)
assign_attributes(attributes)
Setting.transaction do
Setting["locales.default"] = default
Setting["locales.enabled"] = [default, *enabled].join(" ")
end
end
alias_method :update!, :update
end
end