I’m trying to create a feature that allows users to edit a Client entry directly from the index page. When the user clicks ‘Edit’, a partial is rendered which replaces the elements with input text fields. But when the ‘Update client’ button is pressed, I get the error:
"No route matches [POST] "/clients/27"
I’m able to create new clients and destroy clients directly from the index… what am I doing wrong with the update action?
The partial:
<tr id="test">
<%= form_for Client.find(27), :method => :PUT do |f| %>
<td class="input">
<%= f.text_field :name, :value => "Test" %>
</td>
<td class="input">
<%= f.text_field :company %>
</td>
<td class="input">
<%= f.text_field :email %>
</td>
<td class="grayedOut"></td>
<td class="actions">
<%= f.submit "Confirm edit" %>
</td>
<% end %>
</tr>
routes.rb file:
resources :clients do
resources :projects do
resources :items
end
end
I figured it out. For whatever reason, nesting a form inside of a table seems to mess up the way form submits. When I rendered the partial outside of the table, the form had no problem submitting the update action.
I’m still confused as to WHY this happening. My solution to this problem is to use divs instead of tables.
EDIT: OK, so I researched this topic a bit more and found out that ‘forms’ are not valid children of
<table>or<tr>. To fix this problem, I put the<%= form_for %>tag inside of the first<td>, and the<% end %>tag inside of the last<td>. Now it’s working perfectly! Here’s what my partial looks like now: