# Form\_tag and multiple buttons inside problem

**URL:** <https://www.ruby-forum.com/t/form-tag-and-multiple-buttons-inside-problem/52901>\
**Category:** Rails\
**Created:** [January 20, 2006, 2:58am UTC](https://www.ruby-forum.com/t/form-tag-and-multiple-buttons-inside-problem/52901 "2006-01-20T02:58:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santiago\_Hirschfeld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Santiago\_Hirschfeld](https://www.ruby-forum.com/u/Santiago_Hirschfeld)\
**Post date:** [January 20, 2006, 2:58am UTC](https://www.ruby-forum.com/t/form-tag-and-multiple-buttons-inside-problem/52901/1 "2006-01-20T02:58:03Z")

</div>

Hi, I have a bit of a problem with a form in rails. Well, the problem  
really is  
me not fully understanding the mechanism of the form\_tag, so here’s what  
i try  
to do:

The idea is to present a some edit fields for some @product attributes  
and then  
present a table showing the @product.pieces (pieces for every @product)  
and to  
include a “Edit Piece” and “Delete Piece” button in every row of the  
table.  
There’s suppose to be a “Edit Product” and “Create New Piece” at the  
end of the window.

The problem is that (as shown below) the first button does the :action  
=\>  
‘update’ of the form, so doesn’t call update\_piece as it should. Maybe  
I’m not  
being very clear, please excuse my english is not my first language.

Here’s the code for the view.

\<%= start\_form\_tag :action =\> ‘update’,:id =\> @product %\>

```
<label for="product_nombre">Nombre</label>
<%= text_field 'product', 'nombre' %>

<label for="product_descripcion">Descripcion</label>
<%= text_area 'product', 'descripcion', :rows=>4 %>

<label for="product_precio">Precio</label>
<%= text_field 'product', 'precio', 'size' => 8, 'maxlength' => 8 

```

%\>

```
<table>
<tr> <th></th>
    <th>Nombre</th>
    <th>Descripcion</th>
</tr>
<% for p in @product.pieces %>
<tr>
    <td><%= button_to 'Edit Piece', :action => 'edit_piece', :id

```

=\> p %\>

\<%=h p.nombre %\>  
\<%=h p.descripcion %\>  
\<%= button\_to ‘Delete Piece’, :action =\> ‘delete\_piece’,  
:id =\> p %\>  
  
\<% end%\>  

```
<%= button_to 'Edit Product', :action => 'edit', :id => @product -%>
<%= button_to 'Create New Piece', :action => 'add_piece', :id =>

```

@product -%\>

\<%= end\_form\_tag %\>

what I get for the “Edit” button in the generated HTML is the following:

```
blah blah blah HTML code here ....

```

 Piece Name Piece Descrip

---

<div class="post-metadata">

**Author:** ![Santiago\_Hirschfeld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Santiago\_Hirschfeld](https://www.ruby-forum.com/u/Santiago_Hirschfeld)\
**Post date:** [January 20, 2006, 7:22am UTC](https://www.ruby-forum.com/t/form-tag-and-multiple-buttons-inside-problem/52901/2 "2006-01-20T07:22:50Z")

</div>

I don’t not fully understand what you want to do, but if you wanna have  
multiple submit buttons then you need to do some workarounds, becaue RoR  
(or  
better: protoitype.js) has currently some known limitations for that.

Anyway, for non-ajax multiple submit buttons within one form, you just  
put  
several buttons into one form (in your code you are nesting forms, that  
does  
not work, I think), and in the controller you check which button was  
pressed. For ajax, you need to add a hidden field to the form, give it a  
default value and change that value with javascript when the second  
submit  
button was pressed, because serialization in prototype does not support  
multiple submit buttons.

There are code examples for all of this, floating around the web, google  
is  
your friend !
