2010-07-09 60 views
0

我有一個名爲飛機的模型,屈指可數,它是 驅使我堅果。在Rails 3「beta 4」中處理這個問題的正確方法是什麼?如何在使用Rails 3的資源路徑中使用不可數名詞?

resources :aircraft do 
    member do 
    get :flights 
    end 
end 

# Of course these work for some actions and not others. 
match 'aircraft', :to => 'aircraft#index', :as => :aircraft 
match 'aircraft/:id', :to => 'aircraft#show', :as => :aircraft_instance 

回答

0

我認爲這只是:

resources :aircraft, :singular => :aircraft_instance 

然後你link_to他們像這樣:

link_to 'Singular aircraft', aircraft_instance_path(@aircraft) 
link_to 'All aircraft', aircraft_path(@aircraft) 

編輯

它看起來像beta4認爲在複數飛機飛機:

rails console 
> :aircraft.to_s.pluralize 
=> "aircrafts" 

如果你只是把resources :aircraft到您的路線,你可以既link_toaircraft_path(@aircraft)成功aircrafts_path?如果是這樣,您可能需要爲ActiveSupport::Inflector編寫一個初始化程序來定義您自己的自定義變形。

+0

它曾經是這樣的。現在{「singular」=>:aircraft_instance}顯示在請求參數中。是...請求參數,就像我用瀏覽器提交它們一樣。 – 2010-07-09 23:03:35

+0

用新信息更新答案。 – nfm 2010-07-10 01:19:35