Multiple forms on a page


#1

Hello all.

I have the following Code in a view:

<% @dishes.each do |dish| -%>

<%= link_to dish.name, :controller => "restaurant", :action => "show_dish", :id =>"#{dish.id}" -%> <% if dish.vegetarian? -%> <%= image_tag("/images/vegetarian.gif", :class => "bevel", :size => "8x8") %> <% end -%> <%=h dish.summary -%> <%=h dish.price -%> <%= form_tag :action => :add_to_trolley -%> <%= hidden_field_tag("id", "#{dish.id}") -%><%= text_field_tag("fresh","", :size => "2", :value => "0" ) -%> <%= text_field_tag("frozen","", :size => "2", :value => "0") -%> <%= submit_tag("Order") -%> <% end_form_tag -%> <% end -%>

The idea is to present the user with a list of orderlines with an
“Order” button at the end of each line. They fill in the “Fresh” and
“Frozen” values for a line and hit that line’s order button.

What appears to be happening is that the submit button for every line
tries to submit the data in the “Fresh” and “Frozen” values for the
first line ONLY instead of the line in which the order button is part
of. Can anyone see why?

Thanks

Jeff


#2

Have you looked at the html source that is outputted by rails? Can you
post it here? That should give some insight into what’s getting posted,
etc.


#3
<%=h dish.price -%> <%= form_tag :action => :add_to_trolley -%> <%= hidden_field_tag("id", "#{dish.id}") -%><%=
<%= submit_tag("Order") -%> <% end_form_tag -%> <% end -%>

Hmm… just a guess, but it could be because your form tag isn’t
actually in the table. Trying putting the whole form inside a

.
Yes, that might give you problems with formatting, but you could
probably use CSS to fix that: form { display:inline; }