我对我的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
的正确方法是什么?