Search code examples
ruby-on-railsdeviseroutes

Rails routes pointing to different location


I am getting an error when trying to sign out a user. Show and delete user works fine. I get:

NoMethodError in Users#show. 
undefined method `email' for nil:NilClass

Another strange thing I noticed is the parameter passed

Parameters: {"id"=>"sign_out"}

My view:

- if user_signed_in?
  = link_to destroy_user_session_path, class: "nav-link", :action => 'go' do
    .nav-icon.icon-logout
      .lock
         = image_tag("icons/logout.png")
      .unlock
         = image_tag("icons/logout-hover.png")
         Logout
- else
 = link_to new_user_session_path, class: "nav-link", :action => 'go' do
   .nav-icon.icon-login
     .lock
       = image_tag("icons/login.png")
     .unlock
       = image_tag("icons/login-hover.png")
       Login

My routes:

devise_for :users
  resources :users, :only =>[:show]
  match '/users',   to: 'users#index', via: 'get'
  match '/users/:id',     to: 'users#show', via: 'get'
  match '/users/:id' => 'users#destroy', :via => :delete

Solution

  • As posted here On destroying session via Devise "Couldn't find User with 'id'=sign_out" I missed the method: :delete in my view.

    = link_to destroy_user_session_path, method: :delete, class: "nav-link", :action => 'go' do