Forum: Ruby on Rails Multiple forms on a page

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C728d93eb5205cf20cac0c2928b0ad62?d=identicon&s=25 Jeff Jones (Guest)
on 2006-02-27 04:35
Hello all.

I have the following Code in a view:

<% @dishes.each do |dish| -%>
<tr>
<td><%= link_to dish.name, :controller => "restaurant", :action =>
"show_dish", :id =>"#{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", "#{dish.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?

Thanks

Jeff
6283a59f2a604f29df2a4a68b320cc1d?d=identicon&s=25 Chris Johanesen (Guest)
on 2006-02-27 06: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,
etc.
6283a59f2a604f29df2a4a68b320cc1d?d=identicon&s=25 Chris Johanesen (Guest)
on 2006-02-27 06:28
> <td><%=h dish.price -%></td>
>     <%= form_tag :action => :add_to_trolley -%>
> <td><%= hidden_field_tag("id", "#{dish.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.