Forum: Ruby on Rails Multiple forms on a page

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jeff J. (Guest)
on 2006-02-27 05:35
Hello all.

I have the following Code in a view:

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


Chris Johanesen (Guest)
on 2006-02-27 07:26
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,
Chris Johanesen (Guest)
on 2006-02-27 07:28
> <td><%=h dish.price -%></td>
>     <%= form_tag :action => :add_to_trolley -%>
> <td><%= hidden_field_tag("id", "#{}") -%><%=

> <td><%= submit_tag("Order") -%></td>
>     <% 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 <td>.
Yes, that might give you problems with formatting, but you could
probably use CSS to fix that: form { display:inline; }
This topic is locked and can not be replied to.