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.
24 lines
554 B
Ruby
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
|