ruby-on-railsturbolinkshotwire-railsturbohotwire

Hotwire turbo with turbo-method: :delete and redirect_to


My test erb:

<%= link_to 'Test', test_path, data: { turbo_method: :delete } %>

My test controller method looks like this:

def test
  redirect_to root_path, status: :see_other
end

Simple as that.. it responds with a turbostream and appends the response (the root page content) to my html tag instead of redirecting to the root page. Currently using "@hotwired/turbo-rails": "7.2.4"

Is that because turbo_method generates a form and executes inside it / misses the target? I tried several variations of adding a target but it always appends the response..

Shouldn't turbo_method: :delete be the same as rails ujs method: :delete?


Solution

  • 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.