2

我有一個HAS_ONE關係:的Rails 3.1 HAS_ONE嵌套的資源:路由不產生 「全能」 的路徑

# supplier.rb 

    has_one :presentation 
... 

# presentation.rb 

    belongs_to :supplier 
... 

與如下因素嵌套的路線爲他們:

# routes.rb 

resources :suppliers do 
    resource :presentation 
end 

運行rake routes給出:

supplier_presentation POST ... {:action=>"create", :controller=>"presentations"} 
new_supplier_presentation GET ... {:action=>"new", :controller=>"presentations"} 
edit_supplier_presentation GET ... {:action=>"edit", :controller=>"presentations"} 
          GET ... {:action=>"show", :controller=>"presentations"} 
          PUT ... {:action=>"update", :controller=>"presentations"} 
         DELETE ... {:action=>"destroy", :controller=>"presentations"} 

爲什麼show_action沒有name_helper?

我可以覆蓋問題做這樣的事情:

resources :suppliers do 
    resource :presentation, :except => :show do 
    get "" => "presentations#show", as: "presentation" 
    end 
end 

給人路線:

presentation_supplier_presentation GET ... {:controller=>"presentations", :action=>"show"} 

但我們現在都這不是對付它的正確方法..

任何建議?

-

(編輯)

supplier_presentation_path(@supplier) 

的工作,但爲什麼呢? ...當rake routes是在我的shell執行它不會出現......

回答

3

我真的不知道爲什麼,當你做rake routes它沒有顯示,但你在你的代碼試圖做supplier_presentation_path(@supplier)?它應該基於你的路線工作。

+0

它的工作,但** **爲什麼這樣做時,它沒有反映'耙routes' – fgdemussy

+0

我不知道,也許是因爲它是一樣的POST。我在我的一個項目上試過了,它也沒有顯示出來。 – Robin

0

從來沒有它應該爲你工作。試試這個:

link_to "Presentation", [@suplier, @presentation] 

link_to "Presentation", suplier_presentation_path(@suplier, @presentation) 
+0

你不需要@presentation當使用supplier_presentation_path自供應商has_one演示文稿;) – Robin

+0

@Robin,哦,這是真的。我沒有注意到這種關係 – fl00r