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