I'm getting an error message from Rails that it could not find a user with id 'sign_out'. The error comes up when I try to log out of a user session. The application is looking at the GET route instead of the DELETE route that I would like it to.
I've looked through the other posts with similar errors and they suggest that the routes are not configured properly. But I can't seem to figure out what's going on with my application. I've tried several things:
- Switching the order of the devise routes and the user resources
- Calling out the delete method explicitly
- Various combinations of method/destory paths for the link to logout
None of these options seem to work for me.
Here are my relevant files:
routes.rb
Rails.application.routes.draw do
root to: 'welcome#index'
devise_for :users
resources :users, only: [:index,:show]
resources :images, only: [:index, :show, :update]
resources :challenges
end
I also tried nesting and calling out the path directly:
devise_for :users do
get '/users/sign_out' => 'devise/sessions#destroy'
end
resources :users, only: [:index,:show]
my link to log out:
%li= link_to "Logout", destroy_user_session_path, :method => :delete
Running rake routes (relevant routes):
Prefix Verb URI Pattern Controller#Action
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
users GET /users(.:format) users#index
Using the "Log out" link gets this error:
Couldn't find User with 'id'=sign_out
and the parameters associated with the request are:
Request
Parameters:
{"id"=>"sign_out"}
And for whatever reason, the link still generates a GET request:
Started GET "/users/sign_out" for ::1 at 2015-12-25 03:35:11 -0600
Processing by UsersController#show as HTML
Parameters: {"id"=>"sign_out"}
Does anyone have any recommendations on what to change/try next? Let me know if you need more information from any other files.
Aucun commentaire:
Enregistrer un commentaire