Home > other >  No route matches [DELETE] "/users/sign_out" on Rails 6
No route matches [DELETE] "/users/sign_out" on Rails 6

Time:03-10

I just found out about this issue today as I'm reviewing all my projects and all the other posts I found either seem to be about earlier versions of Rails or have solutions I looked into.

I'm trying to sign out my users and I get this error No route matches [DELETE] "/users/sign_out".

Here's my link,

<%= link_to "Sign Out", destroy_user_session_path, method: :delete, :class => 'navbar-link'  %>

My Routes, I'm also using omniauth to sign in with third parties.

devise_for :users, :controllers => { :omniauth_callbacks => "callbacks" }

And here's what I have in devise.rb

config.sign_out_via = :get

The browser's console log gives me this error:

POST http://localhost:3000/users/sign_out 404 (Not Found)

And the Rails log show me this:

Started DELETE "/users/sign_out" for ::1 at 2022-03-06 11:07:46 -0600
  
ActionController::RoutingError (No route matches [DELETE] "/users/sign_out"):

Is there anything I still need to check? Please advise.

CodePudding user response:

Changing config.sign_out_via = :get to config.sign_out_via = [:get, :delete] solved the issue.

Please refer to the comments (thanks again, max). My suggestion is checking Rails UJS before doing the config.sign_out_via = :get, while it might be a solution. It will come back to bite you (like it just did with me). Perhaps, checking if there's a new Rails UJS version or if it's missing from the assets manifest might be better.

  • Related