dynamic-nested-attributes

Implement dynamic nested form fields for Rails has_many associations using Turbo Streams.

6|1|Updated Feb 4, 2026
One-click install
npx skills add https://github.com/RoleModel/rolemodel-skills --skill dynamic-nested-attributes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dynamic-nested-attributes
Source: https://github.com/RoleModel/rolemodel-skills/tree/main/skills/dynamic-nested-attributes
Command: npx skills add https://github.com/RoleModel/rolemodel-skills --skill dynamic-nested-attributes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps Rails developers implement dynamic nested forms that manage has_many associations within a single view, reducing boilerplate and errors when creating or editing related records.

Core Features & Use Cases

  • Dynamic nested form fields for has_many associations with add/remove controls.
  • Turbo Streams-based updates to append or remove nested items without page reloads.
  • Clear guidance for model, form object, views, controller actions, and strong parameters to support bulk operations.

Quick Start

Set up a Rails project, add the turbo-rails and simple_form gems, define a parent model with accepts_nested_attributes_for for the child association, create partials for item fields and a Turbo Stream template that inserts new nested fields, and wire a Stimulus controller to handle client-side removal.

Frequently Asked Questions about dynamic-nested-attributes

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add and remove nested has_many fields dynamically in a Rails form?

To add and remove nested has_many fields dynamically in a Rails form, use Turbo Streams to append or remove partials without a full page reload. This requires accepts_nested_attributes_for on the model and a controller action returning a turbo_stream response.

How do I handle bulk creation and updates for nested attributes in Rails?

Bulk creation and updates for nested attributes in Rails are handled by configuring accepts_nested_attributes_for on the parent model and permitting nested parameters in the controller. The form submits all child records at once for a single transaction save.

Do I need Turbo Streams and Simple Form to build dynamic nested Rails forms?

Yes, Turbo Streams and Simple Form are required to build dynamic nested Rails forms. Turbo Streams handle appending and removing child form partials asynchronously, while Simple Form renders the nested field structure within the parent view.

What is the best way to manage multiple child records inline without a page refresh in Rails?

The best way to manage multiple child records inline without a page refresh in Rails is using Turbo Streams. A controller action builds the new nested item and responds with a turbo_stream template that inserts the rendered partial directly into the form.

How do I configure strong parameters for accepts_nested_attributes_for in Rails?

Configuring strong parameters for accepts_nested_attributes_for requires permitting an array of hashes for the child association attributes. You must whitelist the child model's fields and include the _destroy key if allowing dynamic removal of nested items.

Why are my Turbo Stream nested form updates not rendering the new fields?

Turbo Stream nested form updates fail to render new fields if the controller action does not build the child record correctly or return a turbo_stream format response. Ensure the parent model builds the nested item and the corresponding partial exists for rendering.