Topic: Adding lines to form with AJAX

hey,

i'm a little stuck with some code i'm trying write

what i have is a form for an order. now each order has many order_lines. now, the thing is what i want to do is have an "add line" button, which will render a partial into the form and allow the user to fill out another order line, etc etc ad infinitum.

now, i've got the 'display' end working fine. the button works, adds lines to the form, that's all good. my problem is the processing of this.

how do i handle the data? how can i loop through all the lines in the controller to save them?

here's the code from my order_line view which is rendered every time the user clicks the add line button:

here's the code to the view for the order

----

<table>
    <tr>
        <th><label for="order_line_product">Product:</label></th>
        <th><label for="order_line_maker">Maker:</label></th>
        <th><label for="order_line_unit_price">Unit Price:</label></th>
        <th><label for="order_line_quantity">Quantity:</label></th>
        <th>Subtotal:</th>
    </tr>
    <tr>
        <td><%= text_field "order_line", "product", :size => 30 %></td>
        <td><%= text_field "order_line", "maker", :size => 30 %></td>
        <td><%= text_field "order_line", "unit_price", :size => 15 %></td>
        <td><%= text_field "order_line", "quantity", :size => 15 %></td>
        <td>&nbsp;</td>
    </tr>   
</table>

<div id="orderlines">
   
</div>


<%= link_to_remote("Add Order Line",
                    :update=>"orderlines",
                    :url=>{:action=>"addline"},
                    :position=>"bottom"
                    ) %>
<br />

----

and here's the code to the partial for the order_lines

----

<table>
<tr>
<td><%= text_field "order_line", "product", :size => 30 %></td>
<td><%= text_field "order_line", "maker", :size => 30 %></td>
<td><%= text_field "order_line", "unit_price", :size => 15 %></td>
<td><%= text_field "order_line", "quantity", :size => 15 %></td>
<td>&nbsp;</td>
</tr>
</table>

----

any ideas?

thanks muchly in advance.

Re: Adding lines to form with AJAX

Have you seen this tutorial on the subject?

Railscasts - Free Ruby on Rails Screencasts