destroy_user_session doesn't work in Devise
-
18-04-2021 - |
Question
I'm using rails 3.1.3 and devise 1.5.3 and when I add destroy_user_session_path
to my layout file, the link doesn't work. I can login just fine, but when I click this path I get this error:
No route matches [GET] "/users/sign_out"
BUT, if I run rake routes, I see this route listed:
destroy_user_session DELETE /users/sign_out(.:format)
{:action=>"destroy", :controller=>"devise/sessions"}
So the route clearly uses the DELETE verb. I can get the path to work by adding :method => :delete
, but why do I have to do that? The route is there and configured to be a delete already, so what's up?
Solution
rake routes
shows you what routes your application will respond to. It's up to you to make sure that you generate links that match what the server expects. link_to
does not check to see which verbs are allowed according to the routes - it expects you to supply the correct verb.