[Proposal] fields_for option to generate a template element for easier nested record add/remove

I’m wondering if there is any interest in me submitting a PR for the addition of an option to fields_for which would generate a content template element to be placed before/above the standard output of a fields_for call.

This is useful to me personally when building complex forms with nested records. Often I need to be able to add or remove form entries (usually in the form of a table row), and generally I end up copying an existing row and modifying the id/name indexes. This has the downside of needing to ensure that the last remaining record is not deleted so the add button still has an element to duplicate.

A template element is not rendered on the page but could act as a simple target for cloning, with a predictable index (probably template_index or something) that can be substituted easily with JS.

I have something working but it needs polish and further consideration of the various (daunting) ways that fields_for handles its input.

Hi Thank you for sharing your proposal. Your idea of adding an option to fields_for for generating a content template element sounds promising, especially for complex forms with nested records. The concept of a template element acting as a cloning target with a predictable index could simplify form manipulation.