From 9aca4ae2e01607509b09fe54334b18df54a42663 Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Sun, 10 Nov 2013 10:05:40 -0500 Subject: [PATCH] generate hidden inputs manually to keep markup consistent --- lib/active_admin/form_builder.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/active_admin/form_builder.rb b/lib/active_admin/form_builder.rb index 4e78c3e5bcc..fb61b7002b2 100644 --- a/lib/active_admin/form_builder.rb +++ b/lib/active_admin/form_builder.rb @@ -68,6 +68,15 @@ def has_many(assoc, options = {}, &block) has_many_form.input :_destroy, as: :boolean, wrapper_html: {class: 'has_many_delete'}, label: I18n.t('active_admin.has_many_delete') end + + # generate a hidden input field to keep the mark up consistent + # to disable this, pass for_options: { include_id: false} + # NOTE: has_many_form is a different instance then the one defining this block...has_many_form.object_id != self.object_id + puts "#{has_many_form.class.name} #{has_many_form.object_id} ??? #{self} #{self.object_id}" + if has_many_form.object.persisted? && has_many_form.options.fetch(:include_id, true) && !has_many_form.emitted_hidden_id? + has_many_form.input :id, as: :hidden + end + contents end