On destroying session via Devise Couldn't find User with 'id'=sign_out
resources :users
and devise_for :users
are conflict so
try below code:
routes.rb
Rails.application.routes.draw do
root to: 'visitors#index'
devise_for :users
#resources :users //comment the users resources because its already used by devise_for or used some other resources for users
get "home/index"
get "home/minor"
root to: 'home#index'
end
Additionally, in your config/initalizer/devise.rb
file
Change config.sign_out_via = :delete
to config.sign_out_via = :get
Couldn't find User with id=sign_out
You need to move:
devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy'
over your devise_scope
. Rails is looking for routes from top of Routes file. Your sign out url matches users/:id
, hence it is trying to render show action with sign_out
being an id.
UPDATE:
Actually, do you really need the last line in your devise_scope
block?
Rails/Devise: Couldn't find User with 'id'=sign_out
My application.js file needed the defaulted comments:
//= require jquery
//= require jquery_ujs
My layouts/application.haml file needed the CSRF meta tags:
= csrf_meta_tags
Thanks to sevenseacat for pointing me in the right direction!
Error trying to logout: Couldn't find User with 'id'=sign_out
move get '/users/sign_out' => 'devise/sessions#destroy'
above resources :users
in your routes. Routes are given priority in terms of their order in the routes file.
devise redirect on login error: ActiveRecord::RecordNotFound in DocumentsController#show
I fixed my problem by following this question.Following is my routes.rb
resources :users do
resources :documents, only: [:index]
end
resource :documents, except: [:index]
this gives me document#index path as well as document#new path.
devise destroy session path is conflicting with another user path
In your routes file, you've specified that this route should be matched on a DELETE
request. However, your signout link is sending a GET
request. This is why the request is matching UserControllers#show
.
Assuming you're using jquery
, you can set up this link to send the signout request as DELETE
by making sure you've added jquery_ujs
to the included javascript. This will modify the request method for links that have the data-method
attribute set to something other than 'GET', To specify the proper :method
param for your signout link_to
, use:
link_to "Sign out", destroy_user_session_path, method: :delete
Of course, this will only work if your users have Javascript enabled; otherwise, the request will fallback to GET
anyways. If you want to make signout work for GET
requests, it will need to have higher precedence in your routes file than the show route.
Devise: Why doesn't my logout link work?
The problem lies in the fact that in your logs the signout request is a GET request.
Started GET "/users/sign_out"
But the signout route is a DELETE
destroy_user_session DELETE /users/sign_out(.:format)
The reason why you are getting the exception is that is it getting confused with one of the routes created by resources :users
which would be something like
edit_user GET /users/(:id)(.:format) {:action=>"edit", :controller=>"users"}
Basically 'sign_out' is being mistaken as a id.
I'm not sure why the delete link is not going through as a DELETE request. Though changing
config.sign_out_via = :delete
to be :get
might solve the problem.
Related Topics
Why Sinatra Request Takes Em Thread
Importing CSV as Test Data in Cucumber
Accessing Values Through Ajax Calls and Partials in Rails
How to Schedule a Function to Execute at a Future Time
Why Can't I Create Active Records That Count for Something in Rspec
What's the Differences Between Ruby on Rails and Ruby
How to Seed the Production Database Using the Capistrano Gem
Rails Console Is Not Outputting SQL Statements to My Development Log
Why Does 'Defined' Return a String or Nil
With Nokogiri I am Getting Error "Initialize': Getaddrinfo: No Such Host Is Known. (Socketerror)"
Rails + Google Calendar API Events Not Created
Difference Between "<%=" and "<%" When Mixing Ruby with HTML
Fetching Second Row from CSV File in Ruby