現在我的註銷鏈接的路線指向會話#銷燬,但它不是HTTP刪除動詞,因此它不起作用。這個問題讓我很沮喪,因爲我應該能夠自己弄清楚,但是到目前爲止我還沒有運氣。以下是錯誤信息嘗試登錄時,我得到:註銷鏈接的路由問題? DELETE與GET操作?
沒有路由匹配[刪除]「/註銷」
這裏是我的路線文件:
Rails.application.routes.draw do
get 'line_items/create'
root 'static_pages#home'
get 'testimonials' => 'static_pages#testimonials'
get 'help' => 'static_pages#help'
get 'about' => 'static_pages#about'
get 'contact' => 'static_pages#contact'
get 'signup' => 'users#new'
get 'login' => 'sessions#new'
get 'logout' => 'sessions#destroy'
resources :users
resources :sessions, only: [:new, :create, :destroy]
resources :products
resources :categories
resources :line_items
resources :carts
end
在會議的銷燬方法控制器:
def destroy
forget(current_user)
session.delete(:user_id)
@current_user = nil
redirect_to root_url
end
註銷鏈接:
<li>
<%= link_to "Log out", logout_path, method: "delete" %>
</li>
個
耙路線的相關結果:
logout_path GET /logout(.:format) sessions#destroy
users_path GET /users(.:format) users#index
POST /users(.:format) users#create
new_user_path GET /users/new(.:format) users#new
edit_user_path GET /users/:id/edit(.:format) users#edit
user_path GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions_path POST /sessions(.:format) sessions#create
new_session_path GET /sessions/new(.:format) sessions#new
session_path DELETE /sessions/:id(.:format) sessions#destroy
感謝您的幫助。
發佈$耙的O/P路線| grep註銷你缺少的刪除方法,它不應該得到 – Bijendra 2014-09-24 13:46:31
剛剛發佈耙路線的結果,是的,我知道我只是不知道如何解決這個問題。 – user14346436 2014-09-24 13:51:01