Couldn't find User with id=sign_out
I had the same issue. My routes were in the correct order, the link_to
method was properly used, and Rails kept triggering the users/:id
route with :id => :sign_out
. I figured out that was because I removed jquery_ujs
from my application.js
file...
jquery_ujs
handles the data-method
attribute in the links (generated by link_to
when you use the method option), which is used to determine the correct route as explained here: https://thoughtbot.com/blog/a-tour-of-rails-jquery-ujs
So just make sure the you have the following included in your application.js
:
//= require jquery
//= require jquery_ujs
This worked for me
#form
<%= link_to(destroy_user_session_path, {:class => "nav-link", :method => :delete}) do %>
<span class="sidebar-normal"> Logout </span>
<% end %>
#routes
devise_scope :user do
get '/users/sign_out' => 'devise/sessions#destroy'
end
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?