2016-04-24 73 views
-1

這是我有我的路現在:如何設置路徑以斜線

route

會是什麼格式,將它添加到路由喜歡localhost:3000/appointments/new

+1

請張貼實際的代碼而不是截圖。 – Stefan

+0

你能解釋你的問題嗎?你想輸出什麼? –

+0

我建議你至少設置那些改變狀態爲'POST'或'PUT'的路由。過去有一些不幸的麻煩,瀏覽器預取鏈接到事物並刪除整個數據庫,因爲對「刪除」鏈接等「GET」請求的猖獗。 – tadman

回答

2

使用路由集:

resources :appointments do 
    collection do 
    get :confirm 
    get :cancel 
    get :history 
    end 
end 

它會產生這樣appointments/confirm路線。

+1

他需要通過:身份證也,所以我建議你應該使用,會員路線 – Alfie

+0

您的答案不會在路線中產生任何id,例如:'/ appointmentments /:id/confirm'。但是改爲'/約會/確認'。這是錯誤的。 –

+0

如果他已經有了路線,那他想要什麼理由來寫問題呢? – Ilya

0

正如上面的評論中所建議的那樣。您應該使用member路線:如果你想比任何其他new

 confirm_appointment GET   /appointments/:id/confirm(.:format)  appointments#confirm 
     cancel_appointment GET   /appointments/:id/cancel(.:format)   appointments#cancel 
     history_appointment GET   /appointments/:id/history(.:format)  appointments#history 
      new_appointment GET   /appointments/new(.:format)    appointments#new 

resources :appointments, only: [:new] do 
    member do 
    get :confirm 
    get :cancel 
    get :history 
    end 
end 

其產生以下路線。只需通過only陣列即可。

+0

你的路線和OP路線在圖像上有什麼區別? – Ilya

+0

@llya沒有,除了第一行,他應該得到他想要的。至少在成員路線中,他會根據自己的需要獲取ID。請詳細說明我的答案出了什麼問題。 –

+0

OP詢問了諸如'new'這樣的路線,這是'collection'路線,而不是'member'。這只是一個重構,而不是一個答案。 – Ilya