gpt4 book ai didi

ruby-on-rails - Rails 3.1 has_one 嵌套资源 : routing not generating "all" paths

转载 作者:数据小太阳 更新时间:2023-10-29 08:53:35 24 4
gpt4 key购买 nike

我有一个 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)

确实有效,但是为什么?...在我的 shell 上执行 rake routes 时它没有出现...

最佳答案

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

关于ruby-on-rails - Rails 3.1 has_one 嵌套资源 : routing not generating "all" paths,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7029664/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com