# Editing multiple objects from same model

**URL:** <https://www.ruby-forum.com/t/editing-multiple-objects-from-same-model/123797>\
**Category:** Rails\
**Created:** [December 20, 2007, 6:39pm UTC](https://www.ruby-forum.com/t/editing-multiple-objects-from-same-model/123797 "2007-12-20T18:39:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [December 20, 2007, 6:39pm UTC](https://www.ruby-forum.com/t/editing-multiple-objects-from-same-model/123797/1 "2007-12-20T18:39:00Z")

</div>

I’m trying to build a form that will edit multiple objects from the same  
model. As you can see in the view below, I have a company model that  
has\_many addresses to edit. However, I’m trying to go one further by  
adding the option to this form to add more addresses on the fly… How  
do I do this? Wouldn’t I want to re-render my edit form with an appended  
set of empty fields for the new address in addition to ones that are  
already populated? As you can see I’ve added a link helper at the bottom  
to respond to this request, but what next? I would appreciate any help.  
Thanks.

```auto
   <% form_tag :action => 'update', :id => @company do %>
   <p><label for="company_name">Company Name</label><br/>
   <%= text_field 'company', 'name' %></p>

   <fieldset>
      <legend>Addresses</legend>
      <% for @address in @address %>
        <p><label for="street_1">Street 1</label><br/>
        <%= text_field 'address[]', 'street_1' %></p>
       <p><label for="street_2">Street 2</label><br/>
       <%= text_field 'address[]', 'street_2' %></p>
       <p><label for="city">City</label><br/>
       <%= text_field 'address[]', 'city' %></p>
       <p><label for="state">State</label><br/>
       <%= text_field 'address[]', 'state' %></p>
       <p><label for="zip_code">Zip Code</label><br/>
       <%= text_field 'address[]', 'zip_code' %></p>
     <% end %>
   <%= link_to 'Add new address', :action => 'add_address', :id =>
@company %>
   </fieldset>
   <%= submit_tag 'Edit' %>
   <% end %>
```

---

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [December 22, 2007, 12:34am UTC](https://www.ruby-forum.com/t/editing-multiple-objects-from-same-model/123797/2 "2007-12-22T00:34:57Z")

</div>

go to [railcasts.com](http://railcasts.com) and find complex form. There are 3 episodes.

If you want to add arbitrary number of addresses, I think you will  
need an Addresses model.
