Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
February 21, 2022 07:41 pm GMT

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


Original Link: https://dev.to/spaquet/rails-7-devise-log-out-d1n

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To