So far I've managed to come up with this piece of code:
1 <% @projects.each do |p| %>
2 <%= link_to p.name, project_path(p) %>
3 <%= link_to "edit", edit_project_path(p) %>
4 <%= link_to "delete", project_path(p), :method => :delete %>
5 <% end %>
When I click on 'delete' link it takes me to destroy.html.erb, not delete.html.erb. It also communicates with controllers 'destroy' action, not with 'delete' action. In addition, the URL looks like this /projects/1 (no /delete or /destroy). What is wrong here? Is this the best way to create delete link?
This is the correct behavior of Rails. The :delete method links to the destroy action and adds nothing to the URL -- the proper action is connected by the HTTP verb. For more information on the Rails routing structure and defaults, check out the Rails routing guide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With