我有一个HAS_ONE关系:的Rails 3.1 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)
的工作,但为什么呢? ...当rake routes
是在我的shell执行它不会出现......
它的工作,但** **为什么这样做时,它没有反映'耙routes' – fgdemussy
我不知道,也许是因为它是一样的POST。我在我的一个项目上试过了,它也没有显示出来。 – Robin