Turbo can't be disabled for links with method: post/delete
See original GitHub issueI’ve seen a few issues hovering around this issue (https://github.com/hotwired/turbo-rails/issues/31, https://github.com/hotwired/turbo/issues/45, https://github.com/hotwired/turbo/issues/74). But it seems that disabling turbo is not respected for links with non-GET methods.
I’m attempting to do the following:
link_to "Log Out", destroy_user_session_path, method: :delete, data: { turbo: false }
and the request is always processed as TURBO_STREAM
:
Started DELETE "/users/sign_out" for ::1 at 2021-06-18 13:25:48 -0400
Processing by Users::SessionsController#destroy as TURBO_STREAM
If I use button_to
instead of link_to
, the disabling of turbo works properly.
Versions:
- Ruby Gems:
- rails (6.1.3.2)
- turbo-rails (0.5.9)
- NPMs:
- @hotwired/turbo-rails: 7.0.0-beta.5
- @rails/ujs: 6.1.3
Issue Analytics
- State:
- Created 2 years ago
- Reactions:14
- Comments:18 (2 by maintainers)
Top Results From Across the Web
Link to delete and turbo drive disabled - Hotwire Discussion
I'v got turbo disabled app wide: import '@hotwired/turbo-rails' ... I still had method: :delete in link params, there should be only ...
Read more >My Delete method is not working, after disabling "Turbo" in ...
I'm trying to run my 'Delete' method after disabling 'Turbo' but its not working, it keeps getting to my 'show.html.erb' file instead of ......
Read more >Migrating from Rails UJS to Hotwire: Data Method, Confirm ...
Turbo now provides equivalents to Rails UJS data confirm, disable with, and method attributes that we can use.
Read more >Turbo Drive | The Odin Project
You can disable Turbo Drive by adding data-turbo="false" directly on your links or on the parent containing them. For instance: <div data-turbo="false"> ...
Read more >Turbo Drive Essentials - Akshay's Blog
By default, Turbo links send a GET request to the server. You can change this with the data-turbo-method attribute. <a href= ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
<%= button_to "Delete", url, method: :delete, class: 'button med-button', "data-turbo": false %>
This code works for me, though if I change it to a link_to or remove the data-turbo line it doesnt redirect. Just data-turbo = false or just button_to doesnt work either, it has to be both. And for whatever reason I can’t figure out, it was somehow ending up at my show method for pages instead of redirecting to the page I specified. I dont understand why it just ignores redirects. Doesn’t even get in to the desired controller action.
@fabianzwodrei - I think this is an issue with Devise and XHR requests, and creates problems with Turbo since it uses XHR. Similar issue reported on Stack **Overflow.
I believe this is because devise does not include
status
inredirect_to
wi the session destroy (DELETE) action?see: ActionController::Redirecting
I’m not sure any changes to turbo would solve this.
I think your options are:
params[:_method] = 'DELETE'
.config.sign_out_via = :get
)status
in redirect_to