Module: ActiveAdmin::Globalize3::FormBuilderExtension

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_admin/globalize3/form_builder_extension.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#translated_inputs(name = "Translations", &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active_admin/globalize3/form_builder_extension.rb', line 6

def translated_inputs(name = "Translations", &block)
  form_buffers.last << template.(:div, class: "activeadmin-translations") do
    template.(:ul, class: "available-locales") do
      I18n.available_locales.sort.map do |locale|
        template.(:li) do
          template.(:a, I18n.t(:"active_admin.globalize3.language.#{locale}"), href:".locale-#{locale}")
        end
      end.join.html_safe
    end <<
    I18n.available_locales.sort.map do |locale|
      translation = object.translations.find { |t| t.locale.to_s == locale.to_s }
      translation ||= object.translations.build(locale: locale)
      fields = proc do |form|
        form.input(:locale, as: :hidden)
        form.input(:id, as: :hidden)
        block.call(form)
      end
      inputs_for_nested_attributes(
        for: [:translations, translation ],
        class: "inputs locale locale-#{translation.locale}",
        &fields
      )
    end.join.html_safe
  end
end