« That nobody else could do | Main | Top 5 Bozo Bit Phrases in Email »

link_to '(delete)' {:action => 'delete', :id => recipe.id}

ONLamp.com:

    <% @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 %>

Nice.


July 30, 2006 08:42 PM

Comments

Anthony
(July 30, 2006 07:05 PM #)

Just add :post => true at the end of the link_to call and you are done.