class ActiveAdmin::FormBuilder
def has_many(association, options = {}, &block)
def has_many(association, options = {}, &block) options = { :for => association, :new_record => true }.merge(options) options[:class] ||= "" options[:class] << "inputs has_many_fields" # Add Delete Links form_block = proc do |has_many_form| # @see https://github.com/justinfrench/formtastic/blob/2.2.1/lib/formtastic/helpers/inputs_helper.rb#L373 contents = if block.arity == 1 # for backwards compatibility with REE & Ruby 1.8.x block.call(has_many_form) else index = parent_child_index(options[:parent]) if options[:parent] block.call(has_many_form, index) end if has_many_form.object.new_record? contents += template.content_tag(:li, :class => 'has_many_delete') do template.link_to I18n.t('active_admin.has_many_delete'), "#", :onclick => "$(this).closest('.has_many_fields').remove(); return false;", :class => "button" end elsif options[:allow_destroy] has_many_form.input :_destroy, :as => :boolean, :wrapper_html => {:class => "has_many_remove"}, :label => I18n.t('active_admin.has_many_remove') end contents end form_buffers.last << with_new_form_buffer do template.content_tag :div, :class => "has_many #{association}" do # Allow customization of the nested form heading unless options.key?(:heading) && !options[:heading] form_heading = options[:heading] || object.class.reflect_on_association(association).klass.model_name.human(:count => 1.1) form_buffers.last << template.content_tag(:h3, form_heading) end inputs options, &form_block js = options[:new_record] ? js_for_has_many(association, form_block, template) : "" form_buffers.last << js.html_safe end end end