我對我的routes.rb
的行爲有疑問。下面的代碼完美地工作,但這意味着GET /noodles
和GET /
將返回麪條的索引。因爲noodles_path
將使用/noodles
網址變得不必要的長,它不斷彈出。Rails路線,使用match的資源是什麼?
root :to => 'noodles#index'
match '/new' => 'noodles#new', :as => :new_noodle, :via => [:get]
resources :noodles, :only => [:index, :create, :show]
在試圖移除GET /noodles
這個我試過:
root :to => 'noodles#index'
match '/new' => 'noodles#new', :as => :new_noodle, :via => [:get]
resources :noodles, :only => [:create, :show]
match '/' => 'noodles#index', :as => :noodles, :via => [:get]
這似乎工作,但不知何故,打破了:create
方法,因爲他們都有一個noodles
路徑,即使我指定它到:get
只有它感到困惑(rake routes
看起來不同,noodles
被提及兩次,而當使用resources (...)
它只提到一次)。所以這些新路線不可能創造新的麪條。
刪除GET /noodles
索引並將其設置爲GET /
而不打破:create
的正確方法是什麼?