Method: ActiveAdmin::SimpleForm::SimpleFormBuilder#has_many
- Defined in:
- lib/activeadmin/simple_form/engine.rb
#has_many(assoc, options = {}, &block) ⇒ Object
-> ActiveAdmin::FormBuilder
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/activeadmin/simple_form/engine.rb', line 47 def has_many(assoc, = {}, &block) # -> ActiveAdmin::FormBuilder # remove options that should not render as attributes custom_settings = :new_record, :allow_destroy, :heading, :sortable, :sortable_start = {new_record: true}.merge! .slice *custom_settings = {for: assoc }.merge! .except *custom_settings [:class] = [[:class], "inputs has_many_fields"].compact.join(' ') sortable_column = [:sortable] sortable_start = .fetch(:sortable_start, 0) if sortable_column [:for] = [assoc, sorted_children(assoc, sortable_column)] end html = "".html_safe unless .key?(:heading) && ![:heading] html << template.content_tag(:h3) do [:heading] || assoc_heading(assoc) end end html << template.capture do form_block = proc do |has_many_form| index = parent_child_index [:parent] if [:parent] block_contents = template.capture do block.call(has_many_form, index) end template.concat(block_contents) template.concat has_many_actions(has_many_form, , "".html_safe) end template.assigns[:has_many_block] = true contents = without_wrapper { inputs(, &form_block) } || "".html_safe if [:new_record] contents << js_for_has_many(assoc, form_block, template, [:new_record], [:class]) else contents end end tag = @already_in_an_inputs_block ? :li : :div html = template.content_tag(tag, html, class: "has_many_container #{assoc}", 'data-sortable' => sortable_column, 'data-sortable-start' => sortable_start) template.concat(html) if template.output_buffer html end |