OlderDaze
OlderDaze

Reputation: 61

Rails 3.1 - Devise - CanCan: "../users/sign_out" gets routing error "uninitialized constant UsersController"

"sign_in" works fine but clicking on "sign_out" link locks up during routing (see routes.rb below).

Not sure where to proceed. I'm using RubyMine (IDE) debugger. I click on a link from layout/applications.html.erb:

  <%= link_to('Logout', destroy_user_session_path) %>

RM Debugger watchlist shows: destroy_user_session_path="/user/sign_out"

When I sign_in as a user I breakpoint in "../devise/sessions_controller.rb#sign_in" and that all works fine when I continue.

The status change gives me a "sign_out" link in my applications.html layout but when I click there I get above routine error. I don't get breakpoints in "../application_controller.rb" or "../devise/sessions_controller.rb#sign_out"

Here is routes.rb

Demo::Application.routes.draw do

  # replace devise_for :users with:
  devise_for :users,  :controllers => { :registrations => "devise/registrations" }

  get "user/show"
  get "user/edit"
  get "user/index"
  get "user/create"
  get "user/update"
  get "user/new"

  resources :users

  resources :orders
  resources :carts
  resources :line_items

  resource :store do
    member do
      get "store/index"
    end
  end

  match ':controller(/:action(/:id(.:format)))'

 root       to: 'store#index'
end

And rake:routes

        new_user_session GET    /users/sign_in(.:format)               {:action=>"new", :controller=>"devise/sessions"}
            user_session POST   /users/sign_in(.:format)               {:action=>"create", :controller=>"devise/sessions"}
    destroy_user_session DELETE /users/sign_out(.:format)              {:action=>"destroy", :controller=>"devise/sessions"}
cancel_user_registration GET    /users/cancel(.:format)                {:action=>"cancel", :controller=>"devise/registrations"}
       user_registration POST   /users(.:format)                       {:action=>"create", :controller=>"devise/registrations"}
   new_user_registration GET    /users/sign_up(.:format)               {:action=>"new", :controller=>"devise/registrations"}
  edit_user_registration GET    /users/edit(.:format)                  {:action=>"edit", :controller=>"devise/registrations"}
                         PUT    /users(.:format)                       {:action=>"update", :controller=>"devise/registrations"}
                         DELETE /users(.:format)                       {:action=>"destroy", :controller=>"devise/registrations"}
               user_show GET    /user/show(.:format)                   {:controller=>"user", :action=>"show"}
               user_edit GET    /user/edit(.:format)                   {:controller=>"user", :action=>"edit"}
              user_index GET    /user/index(.:format)                  {:controller=>"user", :action=>"index"}
             user_create GET    /user/create(.:format)                 {:controller=>"user", :action=>"create"}
             user_update GET    /user/update(.:format)                 {:controller=>"user", :action=>"update"}
                user_new GET    /user/new(.:format)                    {:controller=>"user", :action=>"new"}
                   users GET    /users(.:format)                       {:action=>"index", :controller=>"users"}
                         POST   /users(.:format)                       {:action=>"create", :controller=>"users"}
                new_user GET    /users/new(.:format)                   {:action=>"new", :controller=>"users"}
               edit_user GET    /users/:id/edit(.:format)              {:action=>"edit", :controller=>"users"}
                    user GET    /users/:id(.:format)                   {:action=>"show", :controller=>"users"}
                         PUT    /users/:id(.:format)                   {:action=>"update", :controller=>"users"}
                         DELETE /users/:id(.:format)                   {:action=>"destroy", :controller=>"users"}
                  orders GET    /orders(.:format)                      {:action=>"index", :controller=>"orders"}
                         POST   /orders(.:format)                      {:action=>"create", :controller=>"orders"}
               new_order GET    /orders/new(.:format)                  {:action=>"new", :controller=>"orders"}
              edit_order GET    /orders/:id/edit(.:format)             {:action=>"edit", :controller=>"orders"}
                   order GET    /orders/:id(.:format)                  {:action=>"show", :controller=>"orders"}
                         PUT    /orders/:id(.:format)                  {:action=>"update", :controller=>"orders"}
                         DELETE /orders/:id(.:format)                  {:action=>"destroy", :controller=>"orders"}
                   carts GET    /carts(.:format)                       {:action=>"index", :controller=>"carts"}
                         POST   /carts(.:format)                       {:action=>"create", :controller=>"carts"}
                new_cart GET    /carts/new(.:format)                   {:action=>"new", :controller=>"carts"}
               edit_cart GET    /carts/:id/edit(.:format)              {:action=>"edit", :controller=>"carts"}
                    cart GET    /carts/:id(.:format)                   {:action=>"show", :controller=>"carts"}
                         PUT    /carts/:id(.:format)                   {:action=>"update", :controller=>"carts"}
                         DELETE /carts/:id(.:format)                   {:action=>"destroy", :controller=>"carts"}
              line_items GET    /line_items(.:format)                  {:action=>"index", :controller=>"line_items"}
                         POST   /line_items(.:format)                  {:action=>"create", :controller=>"line_items"}
           new_line_item GET    /line_items/new(.:format)              {:action=>"new", :controller=>"line_items"}
          edit_line_item GET    /line_items/:id/edit(.:format)         {:action=>"edit", :controller=>"line_items"}
               line_item GET    /line_items/:id(.:format)              {:action=>"show", :controller=>"line_items"}
                         PUT    /line_items/:id(.:format)              {:action=>"update", :controller=>"line_items"}
                         DELETE /line_items/:id(.:format)              {:action=>"destroy", :controller=>"line_items"}
       store_index_store GET    /store/store/index(.:format)           {:controller=>"store/store", :action=>"index"}
                   store POST   /store(.:format)                       {:action=>"create", :controller=>"stores"}
               new_store GET    /store/new(.:format)                   {:action=>"new", :controller=>"stores"}
              edit_store GET    /store/edit(.:format)                  {:action=>"edit", :controller=>"stores"}
                         GET    /store(.:format)                       {:action=>"show", :controller=>"stores"}
                         PUT    /store(.:format)                       {:action=>"update", :controller=>"stores"}
                         DELETE /store(.:format)                       {:action=>"destroy", :controller=>"stores"}
                                /:controller(/:action(/:id(.:format))) 
                    root        /                                      {:controller=>"store", :action=>"index"}

Robin

Upvotes: 1

Views: 1105

Answers (1)

cailinanne
cailinanne

Reputation: 8372

Change your link to

<%= link_to('Logout', destroy_user_session_path, :method=>'delete') %>     

e.g. add `:method=>'delete'

Upvotes: 6

Related Questions