Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Sjors answer is actually a perfect start to solving the question. I monkeypatched Active Admin in config/initializers/active_admin.rb with the following:</p> <pre><code>module ActiveAdmin class FormBuilder &lt; ::Formtastic::FormBuilder def titled_has_many(association, options = {}, &amp;block) options = { :for =&gt; association }.merge(options) options[:class] ||= "" options[:class] &lt;&lt; "inputs has_many_fields" # Set the Header header = options[:header] || association.to_s # Add Delete Links form_block = proc do |has_many_form| block.call(has_many_form) + if has_many_form.object.new_record? template.content_tag :li do template.link_to I18n.t('active_admin.has_many_delete'), "#", :onclick =&gt; "$(this).closest('.has_many_fields').remove(); return false;", :class =&gt; "button" end else end end content = with_new_form_buffer do template.content_tag :div, :class =&gt; "has_many #{association}" do form_buffers.last &lt;&lt; template.content_tag(:h3, header.titlecase) #using header inputs options, &amp;form_block # Capture the ADD JS js = with_new_form_buffer do inputs_for_nested_attributes :for =&gt; [association, object.class.reflect_on_association(association).klass.new], :class =&gt; "inputs has_many_fields", :for_options =&gt; { :child_index =&gt; "NEW_RECORD" }, &amp;form_block end js = template.escape_javascript(js) js = template.link_to I18n.t('active_admin.has_many_new', :model =&gt; association.to_s.singularize.titlecase), "#", :onclick =&gt; "$(this).before('#{js}'.replace(/NEW_RECORD/g, new Date().getTime())); return false;", :class =&gt; "button" form_buffers.last &lt;&lt; js.html_safe end end form_buffers.last &lt;&lt; content.html_safe end end end </code></pre> <p>Now in my admin file I call titled_has_many just like has_many but I pass in :header to override the use of the Association as the h3 tag.</p> <pre><code>f.titled_has_many :association, header: "Display this as the H3" do |app_f| #stuff here end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload