Rails 3.1 has_one嵌套的资源:路由不生成“ all”消息。路径 [英] Rails 3.1 has_one nested resource: routing not generating "all" paths

查看:48
本文介绍了Rails 3.1 has_one嵌套的资源:路由不生成“ all”消息。路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个has_one关系:

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

运行条耙路给予:

    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

我可以通过以下操作来解决问题:

I can override the problem doing something like:

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

给出路线:

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

但是我们所有人现在都不是正确的处理方法。

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

有任何建议吗?

-

(已编辑)

supplier_presentation_path(@supplier)

可以工作,但是为什么? ......在 rake时不会出现路线在我的shell上执行...

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

推荐答案

我真的不知道为什么在什么时候不显示它您做了耙路,但是您是否尝试在代码中执行 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.

这篇关于Rails 3.1 has_one嵌套的资源:路由不生成“ all”消息。路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆