Reputation: 7434
Rails simulates a DELETE on a resource by using POST and a hidden field in the Form. But that makes it a must to use a form to delete a record. However if I wanted to delete a row via a Anchor tag 'Delete' displayed at the end of the row how would I achieve the same? So say I am displaying people records and my rows looks like:
||First Name|| Last Name||
||Foo || Bar || Delete
||Baz || Foo || Delete
...
And on the delete click I want to route to /people/:id/destroy without using a Form and Hidden field?
Upvotes: 1
Views: 353
Reputation: 20815
Rails' link_to method supports the GET
, POST
, PUT
, and DELETE
HTTP verbs. For example, you could do something like:
link_to "Delete", person_path(@person), method: :delete, confirm: "Are you sure?"
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
Upvotes: 2