Rails 3.1 - 设计 - CanCan:“.. / users / sign_out”获取路由错误“未初始化的常量UsersController”

时间:2011-11-07 19:27:34

标签: ruby-on-rails devise cancan

“sign_in”工作正常但在路由期间点击“sign_out”链接会锁定(请参阅下面的routes.rb)。

不确定从何处着手。我正在使用RubyMine(IDE)调试器。 我点击layout / applications.html.erb中的链接:

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

RM Debugger监视列表显示:destroy_user_session_path =“/ user / sign_out”

当我作为用户签名时,我在“../devise/sessions_controller.rb#sign_in”中断点并且一切正常 我继续时很好。

状态更改在我的applications.html布局中为我提供了“sign_out”链接,但是当我点击时 在那里我遇到了常规错误。我没有在“../application_controller.rb”中获得断点 或“../ devise / sessions_controller.rb#sign_out”

这是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

并且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"}

罗宾

1 个答案:

答案 0 :(得分:6)

将您的链接更改为

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

e.g。添加`:method =&gt;'删除'