Basically,
When you try to type url manually or you try to clickin link "sign-out" with new tab there are HTTP GET request and you will get No route matches [GET] "/users/sign_out"
, it doesn't exist because you have only via DELETE
request for /users/sign_out
on your routes.rb
, for the solution you can add this in config/initializer/devise.rb
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = Rails.env.test? ? :get : :delete
And change DELETE
to MATCH
request on your routes.rb
e.g : match 'users/sign_out' => "devise/sessions#destroy"
For reference : Devise for user management and authentication.
To be honest, supposed change the default 'delete' HTTP method it is not recommended. It's to user for test (e.g using cucumber)
Cucumber Testing for “Sign Out”
Jose Valim explained why: “GET requests should not change the state of
the server. When sign out is a GET request, CSRF can be used to sign
you out automatically and things that preload links can eventually
sign you out by mistake as well.”
@manoj mona's say 'we must not let the user to sign out by typing in the URL. It is a bad practice'
So, If user to sign out by type in the URL.
You can to define it, if get request it will redirect or render notice (like stackoverflow sign out)
Or don't use link_to
tag for sign out, use input
tag with form (like facebook sign out), so users can't type in the URL see this answer