Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 3.1有“一个嵌套资源:路由未生成”;“全部”;路径_Ruby On Rails_Ruby_Ruby On Rails 3_Routing_Nested Resources - Fatal编程技术网

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)