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
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With