the problem: In a nutshell, when I try to install a logout link to my app it fails to work. Here’s as much context as I can think to put here (if you want anything else, please poke me)…
I’ve got this in a haml view:
= link_to("Logout", destroy_user_session_path, :method => :delete)
It generates this in the view:
<a href="/users/sign_out" data-method="delete" rel="nofollow">Logout</a>
I verified that in my config/initializers/devise.rb I have this setting uncommented and correct:
config.sign_out_via = :delete
I validated the following route:
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
I also have this bit of trickery in my routes.rb, and I suspect this is related to my issue:
devise_for :users, :controllers => {:sessions => "devise/sessions", :registrations => "users"}
resources :users
This last bit is because I want to manage (edit, create and delete) users in my own controller.
The error message I’m getting is as follows:
ActiveRecord::RecordNotFound in UsersController#show
Couldn't find User with ID=sign_out
Rails.root: /home/jaydel/projects/mbsquared-projects/Wilson-Goldrick
app/controllers/users_controller.rb:16:in `show'
In my server logs I see this for the request:
Started GET "/users/sign_out" for 127.0.0.1 at 2011-08-04 13:08:51 -0500
Processing by UsersController#show as HTML
Parameters: {"id"=>"sign_out"}
Anyone have any ideas?
The problem lies in the fact that in your logs the signout request is a GET request.
But the signout route is a DELETE
The reason why you are getting the exception is that is it getting confused with one of the routes created by
resources :userswhich would be something likeBasically ‘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
to be
:getmight solve the problem.