Editing multiple objects from same model

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.

   <% 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 %>

go to 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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs