link_to '(delete)' {:action => 'delete', :id => recipe.id}
July 30, 2006 |
co.mments
<% @recipes.each do |recipe| %>
<tr>
<td>
<%= link_to recipe.title,
:action => "show",
:id => recipe.id %>,
<font size=-1>
<%= link_to "(delete)",
{:action => "delete", :id => recipe.id}
:confirm => "Really delete #{recipe.title}?" %>
</font>
</td>
<td><%= recipe.category.name %></td>
<td><%= recipe.date %></td>
</tr>
<% end %>

I know it's a tutorial (otherwise a good one) but that's pretty bad. Destruction over GET is a worst practice. Assuming that isn't idiomatic Rails any more, an update to that article that uses a POST form would be much appreciated. It's Rails, it'll take 5 minutes - right?
Update: not even five minutes! Anthony Eden say to add ":post =>true" on the action.
<% @recipes.each do |recipe| %>
<tr>
<td>
<%= link_to recipe.title,
:action => "show",
:id => recipe.id %>
<font size=-1>
<%= link_to "(delete)",
{:action => "delete", :id => recipe.id}, ,:post =>true
:confirm => "Really delete #{recipe.title}?" %>
</font>
</td>
<td><%= recipe.category.name %></td>
<td><%= recipe.date %></td>
</tr>
<% end %>
July 30, 2006 08:42 PM
Comments
Just add :post => true at the end of the link_to call and you are done.