Rails 宁静的命名空间、资源...新手问题
我正在尝试使用具有静态路径的嵌套控制器,以便我一切都井然有序。到目前为止,这是我的routes.rb的副本:
map.root :controller => "dashboard"
map.namespace :tracking do |tracking|
tracking.resources :companies
end
map.namespace :status do |status|
status.resources :reports
end
指向子控制器路径的链接现在工作正常,
<%= link_to "New Report", new_status_report_path, :title => "Add New Report" %>
但是当我尝试仅映射到父控制器的索引路径时,我的问题随之而来。
<%= link_to "Status Home", status_path, :title => "Status Home" %>
当我加载带有链接的页面时,我最终得到了这个:
undefined local variable or method `status_path'
我的路线是否为这种链接设置正确?
更新:我应该补充一点,没有数据与父“状态”控制器关联。它仅充当与状态相关的其余控制器的类别占位符,例如:报告。
I'm attempting to use nested controllers that have restful pathing, so that I'm all organized and such. Here's a copy of my routes.rb so far:
map.root :controller => "dashboard"
map.namespace :tracking do |tracking|
tracking.resources :companies
end
map.namespace :status do |status|
status.resources :reports
end
Links to children controller paths work fine right now,
<%= link_to "New Report", new_status_report_path, :title => "Add New Report" %>
But my problem ensued when I tried to map to just the parent controller's index path.
<%= link_to "Status Home", status_path, :title => "Status Home" %>
I end up getting this when I load the page with the link:
undefined local variable or method `status_path'
Are my routes set correctly for this kind of link?
UPDATE: I should add that no data is associated with the parent "status" controller. It merely acts as the category placeholder for the rest of the controllers associated with statuses, eg: reports.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望 /status 转到状态控制器,它应该是资源,而不是命名空间。您可以以大致相同的方式嵌套资源:
If you want /status to go to the status controller it should be a resource, not a namespace. You nest resources in much the same way:
命名空间不是资源。
此外,您对 status_path 的调用需要一个 ID。
status_path(:id => @status.id)
或
status_path(@status)
A namespace isn't a resource.
Also, your call to status_path needs an ID.
status_path(:id => @status.id)
or
status_path(@status)