2012-10-21 84 views
0

我正在跟着Michael Hartl的Ruby on Rails Tutorial 2nd Edition,並已到達本書的登錄/註釋部分。Rails路線錯誤

到目前爲止,我可以創建一個新用戶(或在我的情況下,房東),並使用新的憑據登錄。我的問題是退出時出現問題。我點擊 「signout」,並獲得路線錯誤說:

沒有路由匹配[GET] 「/ signout」

下面是代碼片段。任何幫助將非常感激!

耙路線輸出

landlords GET /landlords(.:format)   landlords#index 
       POST /landlords(.:format)   landlords#create 
    new_landlord GET /landlords/new(.:format)  landlords#new 
edit_landlord GET /landlords/:id/edit(.:format) landlords#edit 
     landlord GET /landlords/:id(.:format)  landlords#show 
       PUT /landlords/:id(.:format)  landlords#update 
       DELETE /landlords/:id(.:format)  landlords#destroy 
    properties GET /properties(.:format)   properties#index 
       POST /properties(.:format)   properties#create 
    new_property GET /properties/new(.:format)  properties#new 
edit_property GET /properties/:id/edit(.:format) properties#edit 
     property GET /properties/:id(.:format)  properties#show 
       PUT /properties/:id(.:format)  properties#update 
       DELETE /properties/:id(.:format)  properties#destroy 
     sessions POST /sessions(.:format)   sessions#create 
    new_session GET /sessions/new(.:format)  sessions#new 
     session DELETE /sessions/:id(.:format)  sessions#destroy 
      root  /       content_pages#home 
content_pages_home GET /content_pages/home(.:format) content_pages#home 
      help  /help(.:format)    content_pages#help 
    questions  /questions(.:format)   content_pages#questions 
     signup  /signup(.:format)    landlords#new 
     signin  /signin(.:format)    sessions#new 
     signout DELETE /signout(.:format)    sessions#destroy 

的routes.rb文件

resources :landlords 
    resources :properties 
    resources :sessions, only: [:new, :create, :destroy] 

    root :to => 'content_pages#home' 

    get "content_pages/home" 

    match '/help', to: 'content_pages#help' 
    match '/questions', to: 'content_pages#questions' 
    match '/signup', to: 'landlords#new' 
    match '/signin', to: 'sessions#new' 
    match '/signout', to: 'sessions#destroy', via: :delete 

連結signout

<%= link_to "Signout", signout_path, method: "delete" %> 

會話控制器

def destroy 
    sign_out 
    redirect_to root_path 
end 
+0

你在會話助手中有一個'sign_out'方法嗎?請看書/網站上的清單8.30。控制器的'destroy'方法正在尋找它。 – Bert

+0

是啊,我在會議助手簽出法「高清SIGN_OUT \t self.current_landlord =零 \t cookies.delete(:remember_token) \t年底」 –

+0

嘿@TonyStaunton爲你所做的答案的工作?我仍然有同樣的問題。 –

回答

4

在下面的代碼的via:選項限制請求刪除方法:

match '/signout', to: 'sessions#destroy', via: :delete 

你需要做一個與「讓」方法的工作

退房的Rails Routing guide