Ruby on rails Rails 3.1有“一个嵌套资源:路由未生成”;“全部”;路径
我有一个关系:Ruby on rails Rails 3.1有“一个嵌套资源:路由未生成”;“全部”;路径,ruby-on-rails,ruby,ruby-on-rails-3,routing,nested-resources,Ruby On Rails,Ruby,Ruby On Rails 3,Routing,Nested Resources,我有一个关系: # supplier.rb has_one :presentation ... # presentation.rb belongs_to :supplier ... 以及它们的以下嵌套路由: # routes.rb resources :suppliers do resource :presentation end 运行rake路由将提供: supplier_presentation POST ... {:action=>"create",
# supplier.rb
has_one :presentation
...
# presentation.rb
belongs_to :supplier
...
以及它们的以下嵌套路由:
# routes.rb
resources :suppliers do
resource :presentation
end
运行rake路由
将提供:
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"}
为什么没有显示动作的名称\u助手?
我可以通过执行以下操作来解决此问题:
resources :suppliers do
resource :presentation, :except => :show do
get "" => "presentations#show", as: "presentation"
end
end
给出路线:
presentation_supplier_presentation GET ... {:controller=>"presentations", :action=>"show"}
但我们现在都知道这不是正确的处理方式
有什么建议吗?
--
(已编辑)
确实有效,但为什么?。。。当在我的shell上执行
rake routes
时,它不会出现…我真的不知道为什么在执行rake routes
时它不会显示,但您是否尝试在代码中执行供应商演示路径(@supplier)
?它应该根据你的路线来工作。它应该对你更有效。试试这个:
link_to "Presentation", [@suplier, @presentation]
或
它确实有效,但为什么在做
rake routes
时没有反映出来呢?我不知道,可能是因为它和帖子一样。我在我的一个项目上试用了它,但它也没有显示。在使用supplier\u presentation\u路径时,您不需要@presentation,因为supplier有一个演示;)@罗宾,哦,那是真的。我没有注意到这种关系
link_to "Presentation", [@suplier, @presentation]
link_to "Presentation", suplier_presentation_path(@suplier, @presentation)