Reputation: 141
When I try to sign out i am getting error of No route matches [GET] "/users/sign_out". this is my link tag for Signout.
<%= link_to "Sign Out", destroy_user_session_path, method: :get , class: "nav-link" %>
Here is what my routes related to my User model and Devise look like:
Rails.application.routes.draw do
devise_for :users do
get '/users/sign_out' => 'devise/sessions#destroy'
end
root 'books#index'
resources :books do
member do
put "like", to: "books#upvote"
end
end
end
And this is my devise.rb
config.sign_out_via = :get
Upvotes: 4
Views: 4026
Reputation: 4437
Question similar to:
No route matches [GET] “/users/sign_out”
Please check my answer there (the one here got deleted)
Upvotes: 0
Reputation: 17
Since you are destroying the session, it is not a :get
method but a :delete
. Modify the link to:
= link_to "Log out", destroy_user_session_path, method: :delete
Upvotes: 0
Reputation: 31
Make sure of this:
in your Gemfile include
gem 'jquery-rails'
in application.js
//= require jquery
//= require jquery_ujs
In my opinion is not so good change the routers or the method to sign out, this action should be done always with DELETE. That worked for me.
Upvotes: 3
Reputation: 654
If you intend to keep the default route path for signout /users/sign_out
, then instead of doing this:
devise_for :users do
get '/users/sign_out' => 'devise/sessions#destroy'
end
The way it should be handled is one of two ways:
Use DELETE method instead of GET
<%= link_to "Sign Out", destroy_user_session_path, method: :delete, class: "nav-link" %>
-OR-
Edit your devise.rb initializer and change
config.sign_out_via = :delete
to config.sign_out_via = :get
Upvotes: 5
Reputation: 2610
Try the following in routes.rb
devise_for :users
devise_scope :user do
get '/users/sign_out' => 'devise/sessions#destroy'
end
for more information how to by devise
Upvotes: 13