2016-04-07 44 views
0

這裏是代碼我routes.rb軌道路由到SESSION_INDEX代替會議

Rails.application.routes.draw do 
    resources :session, only: [:create, :destroy, :new] 
end 

rake routes相關的輸出是

session_index POST /session(.:format)  session#create 
new_session GET /session/new(.:format) session#new 
session  DELETE /session/:id(.:format) session#destroy 

我的問題是,爲什麼session#create路線session_index,而不是隻需session

回答

1

它應該是:

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

按Rails約定,如果使用singular資源,然後只需使用resourceplural資源,你應該使用resources

Resource Routing

+0

解決了這個問題,謝謝 – rainbowsorbet