Simple method delete with confirm

i tried it with link_to and button_to… my button_to example looks like this:

<%= button_to 'Delete', item_path(object), method: :delete, form: { data: { turbo_confirm: 'Really?' } } %>

and in my controller action it’s just a simple redirect

def destroy
  redirect_to items_path, status: :see_other
end

the confirm shows up - also the redirect gets executed but it does not really redirect the page - it appends the html content of the redirect to the current page html tag… i’m not sure whats wrong i’m pulling out my hair… i mean it can’t be that hard - it should do a regular redirect - right?

package.json version “@hotwired/turbo-rails”: “7.2.4”
gemfile.lock turbo-rails 1.3.3

2 Likes

Is it possible that you are inside a <turbo-frame>, and the content is being loaded into that frame (as opposed to replacing the entire Body content)?

hm nope unfortunately not - no turbo-frame tag upwards in html tree

I found the problem. when the view method which it gets redirected to - does not have a declared respond_to format for html or the html template has no html in the file name like index.slim turbo_stream does not know how to handle it and it appends it instead of replacing the whole page.

1 Like