# Repeatable Form Elements

**URL:** <https://www.ruby-forum.com/t/repeatable-form-elements/141365>\
**Category:** Rails\
**Created:** [June 25, 2008, 1:55am UTC](https://www.ruby-forum.com/t/repeatable-form-elements/141365 "2008-06-25T01:55:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [June 25, 2008, 1:55am UTC](https://www.ruby-forum.com/t/repeatable-form-elements/141365/1 "2008-06-25T01:55:59Z")

</div>

Does anyone know any good “recipe” to have repeatable form elements in  
Ruby on Rails sites?

As an example, let’s say I want users to be able to add as many  
addresses as possible. An address object consists of two address  
lines, a city id, and a country id. They can click “Add Another  
Address” and more address inputs are created on the fly.

[Javascript - Extending forms](http://www.quirksmode.org/dom/domform.html) - imagine this as an  
example

1. How do you set the names of the form elements in rails so that they  
are processed easily? Can you even do this with helpers, or would the  
necessary elements need to be written and parsed manually?  
ex. address[:city][], address[:state][]

2. Is there an easy way to keep track of addresses on the page once  
they are added, assuming they can be updated in text fields? For  
example, after someone adds an address, and reloads the page, can you  
say:  
address[1][:city], or some other name and then have Rails parse this  
correctly as an object in the params? This would need to also be  
differentiated from the naming convention in #1, to differentiate  
existing address objects from new ones.

Anyone have any ideas or articles that deal with this issue, or hints  
on how to make this easier?

Thanks.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [June 25, 2008, 3:00am UTC](https://www.ruby-forum.com/t/repeatable-form-elements/141365/2 "2008-06-25T03:00:17Z")

</div>

I think this episode might help you…

> **[\#75 Complex Forms Part 3 - RailsCasts](http://railscasts.com/episodes/75-complex-forms-part-3)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [June 25, 2008, 6:14pm UTC](https://www.ruby-forum.com/t/repeatable-form-elements/141365/3 "2008-06-25T18:14:40Z")

</div>

See those same Railscasts to which shenry cited David S. for one  
way to do multiple object creation on a single form:

> **[\#73 Complex Forms Part 1 - RailsCasts](http://railscasts.com/episodes/73-complex-forms-part-1)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

> **[\#74 Complex Forms Part 2 - RailsCasts](http://railscasts.com/episodes/74-complex-forms-part-2)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

> **[\#75 Complex Forms Part 3 - RailsCasts](http://railscasts.com/episodes/75-complex-forms-part-3)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.
