---
title: "Persisting nested form attribute indexes through Turbo updates"
description: "When a Turbo Stream replaces part of a Rails nested form, the replacement fields must keep the same attribute index as their siblings, which can be passed via the form builder's `index` property as a URL parameter and hidden field."
url: "https://swe.quest/articles/persisting-nested-form-attribute-indexes-through-turbo-updates-0b3175a90493222c"
canonical: "https://engineering.freeagent.com/2026/01/08/persisting-nested-form-attribute-indexes-through-turbo-updates/"
source: "FreeAgent Engineering"
published: "2026-01-08"
difficulty: "medium"
kind: "How-to"
reading_minutes: 5
tags: ["ruby","frontend"]
---

# Persisting nested form attribute indexes through Turbo updates

A post on [FreeAgent Engineering](https://swe.quest/sources/freeagent.md), published 2026-01-08, 5 min read, How-to. Original: [https://engineering.freeagent.com/2026/01/08/persisting-nested-form-attribute-indexes-through-turbo-updates/](https://engineering.freeagent.com/2026/01/08/persisting-nested-form-attribute-indexes-through-turbo-updates/)

## Summary

When a Turbo Stream replaces part of a Rails nested form, the replacement fields must keep the same attribute index as their siblings, which can be passed via the form builder's \`index\` property as a URL parameter and hidden field. This breaks for rows added client-side with JavaScript templates and timestamp indexes, because the form builder never learns the index and links carry a blank value. FreeAgent fixed it by moving the "Add Another" behaviour to a server-rendered Turbo Stream that sets a timestamp index on \`fields\_for\`, removing the client-side templating duplication entirely.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Ruby](https://swe.quest/tags/ruby.md) (Languages)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)

## Prerequisites

- Rails form helpers ([easy posts on Ruby](https://swe.quest/tags/ruby.md?difficulty=easy))
- Hotwire Turbo Streams
- nested attributes in Rails ([easy posts on Ruby](https://swe.quest/tags/ruby.md?difficulty=easy))

## Keywords

Ruby on Rails, Turbo Streams, Action View, fields\_for, Hotwire, FreeAgent

## Related posts

- [How DatoCMS solved tag invalidation with Turso](https://swe.quest/articles/how-datocms-solved-tag-invalidation-with-turso-1cbed129b2d71763.md): Turso · 2024-07-15 · Easy · 3 min read · Caching, SQLite, Frontend
  DatoCMS's Content Delivery API attaches cache tags to every response and sends invalidated tags to the frontend via webhook, but Next.js limits a cache item to 64 tags.
- [Changing a polymorphic\_type in Rails](https://swe.quest/articles/changing-a-polymorphic-type-in-rails-8b5924e77ba397de.md): Shopify Engineering · 2022-02-18 · Medium · 7 min read · Ruby, Refactoring & migrations, Schema migrations, Databases
  Rails stores the parent's class name in a polymorphic association's type column, so moving models into a new namespace (e.g. Car to Garage::Car) leaves mixed values like "Car" and "Garage::Car" and breaks lookups in both directions.
- [Incident 2023-12-04: Data leak and loss in some free tier databases](https://swe.quest/articles/incident-2023-12-04-data-leak-and-loss-in-some-free-tier-databases-f301d07a6ce79951.md): Turso · 2023-12-05 · Medium · 3 min read · Incidents & postmortems, Multi-tenancy, Storage systems, Security, Serverless
  A migration bug introduced on November 20 left 0.07% of Turso free-tier databases with an empty backup identifier, so they all pointed at a shared S3 prefix (s3://bucket//) instead of per-database paths.
- [You can now migrate your existing databases to AWS](https://swe.quest/articles/you-can-now-migrate-your-existing-databases-to-aws-664f4db954322a62.md): Turso · 2025-05-12 · Medium · 4 min read · SQLite, Databases, Cloud platforms
  Turso paid-plan users can move database groups from Fly.io to AWS with new \`turso group aws-migration info/start/abort\` CLI commands; free-tier users have already been migrated.
- [Introducing Bobbin](https://swe.quest/articles/introducing-bobbin-38b7a32c2aaf86ba.md): Tangled · 2026-07-13 · Medium · 7 min read · System design, Caching, Distributed systems, Deployment
  Bobbin is a read-only, API-only AppView for Tangled that serves the sh.tangled.\* atproto lexicons over XRPC while holding everything in RAM.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
