英文:
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`?
英文:
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
?
答案1
得分: 0
我找到了问题。当view
方法被重定向到时,如果没有为HTML声明respond_to
格式,或者HTML模板的文件名中没有包含"html",比如index.slim
,turbo_stream
就不知道如何处理它,而是附加它而不是替换整个页面。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论