No route matches on user sign out with Rails 7

No route matches on user sign out with Rails 7

I've finally upgraded my Rails web application template to Rails 7. The gems I use for authentication is Devise. As I was doing the port, I ran into the issue where I was getting the following error:

No route matches [GET] "/users/sign_out"

My code looked like this:

<%= link_to "Sign out", destroy_user_session_path, method: :delete, id: "sign_out_menu_link", class: "dropdown-item" %>

Given that I haven't changed my code since Rails 5, I was a bit baffled by why this was happening to me.

After doing some reading, this stopped working because Rails 7 now uses Turbo and the method needs to be called a bit differently. So the fixed code now looks like this:

<%= link_to "Sign out", destroy_user_session_path, data: { turbo_method: :delete }, id: "sign_out_menu_link", class: "dropdown-item" %>

Referral link