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

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 %>
$ <%= @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
index or something…using which you can index your keys. But for
problem lies…within the fact that…ideally <%= file_field :picture
“image” %>, here image should be a method within the model
i have a array of images…then how can i assign same key to all of

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

If i do this then the parameters passed will be

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.

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