Rails 7 + Devise + Log out

A Quick and Dirty way to get the redirection working on Logout when using Devise in a Rails 7 app.

You probably have noticed that most of the redirects in Devise a somehow broken. This is due to the way Turbo interfere with them as it catches the 200 …


This content originally appeared on DEV Community and was authored by Stéphane

A Quick and Dirty way to get the redirection working on Logout when using Devise in a Rails 7 app.

You probably have noticed that most of the redirects in Devise a somehow broken. This is due to the way Turbo interfere with them as it catches the 200 status code.

There are already a lot of posts explaining how to patch this while waiting for an official release. But, if your main issue is about the "redirect on log out" not working, then you can easily fix this.

Instead of calling destroy_user_session_path in a link_to, call it inside of a button_to

Here is the full code:

<%= button_to(
        "Log Out",
        destroy_user_session_path,
        method: :delete
      ) %>

And Voilà! This simple hack enables your users to be redirected to the root_path of your app in seconds.


This content originally appeared on DEV Community and was authored by Stéphane


Print Share Comment Cite Upload Translate Updates
APA

Stéphane | Sciencx (2022-02-21T19:41:47+00:00) Rails 7 + Devise + Log out. Retrieved from https://www.scien.cx/2022/02/21/rails-7-devise-log-out/

MLA
" » Rails 7 + Devise + Log out." Stéphane | Sciencx - Monday February 21, 2022, https://www.scien.cx/2022/02/21/rails-7-devise-log-out/
HARVARD
Stéphane | Sciencx Monday February 21, 2022 » Rails 7 + Devise + Log out., viewed ,<https://www.scien.cx/2022/02/21/rails-7-devise-log-out/>
VANCOUVER
Stéphane | Sciencx - » Rails 7 + Devise + Log out. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/21/rails-7-devise-log-out/
CHICAGO
" » Rails 7 + Devise + Log out." Stéphane | Sciencx - Accessed . https://www.scien.cx/2022/02/21/rails-7-devise-log-out/
IEEE
" » Rails 7 + Devise + Log out." Stéphane | Sciencx [Online]. Available: https://www.scien.cx/2022/02/21/rails-7-devise-log-out/. [Accessed: ]
rf:citation
» Rails 7 + Devise + Log out | Stéphane | Sciencx | https://www.scien.cx/2022/02/21/rails-7-devise-log-out/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.