2

我有一个 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 动作没有 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...在我的外壳上执行时没有出现...

4

2 回答 2

3

我真的不知道为什么当你这样做时它没有显示,rake routes但你有没有尝试在你的代码中这样做supplier_presentation_path(@supplier)?它应该根据您的路线工作。

于 2011-08-11T16:46:15.723 回答
0

无论如何,它应该为你工作。尝试这个:

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

或者

link_to "Presentation", suplier_presentation_path(@suplier, @presentation)
于 2011-08-11T16:47:02.990 回答