Destroy record in turbo-frame

You’ll want to submit a form rather than click a link. The button_to method will be your friend.

If you’re rendering that link with link_to, the change will be dead easy:

# You’ll change something like this...

<%= link_to "Delete", post, data: { method: :delete } %>

# to this...

<%= button_to "Delete", post, method: :delete %>

In hindsight, it was probably a bad idea for rails ujs to hijack links to make non-GET requests. It works against the grain of HTML. A link doesn’t make something happen, it takes you somewhere. HTML gives you a separate tool to make something happen, which is a form. (See https://twitter.com/sstephenson/status/1341735693077327874 for where I originally saw this thought expressed.)

6 Likes