# Form with multiple rows of content

**URL:** <https://www.ruby-forum.com/t/form-with-multiple-rows-of-content/58629>\
**Category:** Rails\
**Created:** [April 24, 2006, 9:27am UTC](https://www.ruby-forum.com/t/form-with-multiple-rows-of-content/58629 "2006-04-24T09:27:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikhilesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/46a35a/32.png) [@Nikhilesh](https://www.ruby-forum.com/u/Nikhilesh)\
**Post date:** [April 24, 2006, 9:27am UTC](https://www.ruby-forum.com/t/form-with-multiple-rows-of-content/58629/1 "2006-04-24T09:27:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nikhilesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/46a35a/32.png) [@Nikhilesh](https://www.ruby-forum.com/u/Nikhilesh)\
**Post date:** [April 24, 2006, 3:27pm UTC](https://www.ruby-forum.com/t/form-with-multiple-rows-of-content/58629/2 "2006-04-24T15:27:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Nikhilesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/46a35a/32.png) [@Nikhilesh](https://www.ruby-forum.com/u/Nikhilesh)\
**Post date:** [April 25, 2006, 12:24am UTC](https://www.ruby-forum.com/t/form-with-multiple-rows-of-content/58629/3 "2006-04-25T00:24:04Z")

</div>

yeah its really simple:

\<%= text\_field “item”, “quantity”, :index =\> @item.unit\_price %\>

---

<div class="post-metadata">

**Author:** ![Nikhilesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/46a35a/32.png) [@Nikhilesh](https://www.ruby-forum.com/u/Nikhilesh)\
**Post date:** [April 26, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/form-with-multiple-rows-of-content/58629/4 "2006-04-26T22:52:46Z")

</div>

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.
