Rails 3.1 has_one 嵌套资源:路由不生成“所有”资源路径

发布于 2024-11-29 03:40:23 字数 1495 浏览 1 评论 0原文

我有一个 has_one 关系:

# supplier.rb

  has_one :presentation
...

# presentation.rb

  belongs_to :supplier
...

以及它们的以下嵌套路由:

# routes.rb

resources :suppliers do
  resource :presentation
end

运行rake paths给出:

    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"}

为什么没有 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 paths 时它不会出现...

I have a has_one relation:

# supplier.rb

  has_one :presentation
...

# presentation.rb

  belongs_to :supplier
...

and the folowing nested routes for them:

# routes.rb

resources :suppliers do
  resource :presentation
end

running rake routesgives:

    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"}

Why no name_helper for the show action?

I can override the problem doing something like:

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

giving the route:

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

but we all now that's not the right way to deal with it..

ANY SUGGESTIONS?

--

(edited)

supplier_presentation_path(@supplier)

does work, but why?... It doesn't appear when rake routes is executed on my shell...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

往事随风而去 2024-12-06 03:40:23

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

I dont really know why it's not displayed when you do rake routes but did you try in your code to do supplier_presentation_path(@supplier)? It should work based on your routes.

左秋 2024-12-06 03:40:23

尽管如此,它应该对你有用。试试这个:

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

或者

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

Never the less it should work for you. Try this:

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

or

link_to "Presentation", suplier_presentation_path(@suplier, @presentation)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文