Skip to content

Handling delete routes #44

Closed
hotwired/turbo
#409
@olliekav

Description

@olliekav

Excuse me if I'm missing something obvious here, but this seems like a pretty common use case and I'm not sure how to handle it.

If I use the default Rails way of deleting a record...

<%= button_to event_path(@event), method: :delete, data: { confirm: 'Delete this event?' }, class: 'button button--link' do %>
      Delete event
<% end%>

This defaults to .advance so you end up pushing the redirected view (in this case the index list view of events) onto the stack and having a back button to go back to a view that no longer exists. How do you handle delete routes? Currently I'm having to write some custom regex in my Turbo coordinator to see if the activeVisitable URL was the show view and the next url is the index view and act as though that is deleting.

I tried data-turbo-action="replace" based on https://github.com/hotwired/turbo/pull/231/files but that doesn't seem to be working on any forms. This always defaults to .advance and is never picked up by the proposal.

<%= form_for(@event, url: events_path, html: { data: { "turbo-action": "replace" }}) do |f| %>
<%= button_to event_path(@event), method: :delete, data: { confirm: 'Delete this event?' }, form: { 'data-turbo-action': 'replace' } do %>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions