Form with multiple rows of content

I have looked at examples for this. I found a similar example in the
Agile Web Dev… book but that didn’t help. Here’s what i am trying to
do.

A Cart has many line items. On the Display Cart page, I want to provide
the user the option to update quantities.

Here’s the rhtml code:
<%= start_form_tag :action => ‘update_cart’ %>
<% for @item in @items %>
<%= @item.product.title %>
<%= text_field “item[]”,‘quantity’ %>
<%= number_to_currency(@item.unit_price) %>
$<%= @item.quantity * @item.unit_price %>
<%= link_to ‘Remove item’, {:action => ‘remove_from_cart’, :id =>
@item.product} %>
<% end %>
Total
$ <%= @cart.total_price %>
<%= submit_tag ‘Update Cart’ %>
<%= end_form_tag %>

In the Page->View source I find that all text boxes have the name
item[quantity]. I expected the names to be item[0][quantity],
item[1][quantity] and so on.
And instead of passing all the rows as params, only the first row (i.e.
first line item) is being passed to the update_cart function.

I’ve spent 3 days on this. Please help !!

Though i am having similar kind of problem…but there is a option
called
index or something…using which you can index your keys. But for
me…real
problem lies…within the fact that…ideally <%= file_field :picture
“image” %>, here image should be a method within the model
class…now…if
i have a array of images…then how can i assign same key to all of
them?

yeah its really simple:

<%= text_field “item”, “quantity”, :index => @item.unit_price %>

hemant kumar wrote:

yeah its really simple:

<%= text_field “item”, “quantity”, :index => @item.unit_price %>

Thanks.
If i do this then the parameters passed will be
item[0]=>quantity=>n1
item[1]=>quantity=>n2
item[2]=>quantity=>n3

and so on…

How do i read this at the server? Now this becomes a Ruby language
question actually and not a Rails question.

This is just an enhancement to the Depot application in the Agile Web
Dev book. The objective is to update all the quantities of all the line
items of the cart.