Rails 宁静的命名空间、资源...新手问题

发布于 2024-09-11 16:18:44 字数 760 浏览 6 评论 0原文

我正在尝试使用具有静态路径的嵌套控制器,以便我一切都井然有序。到目前为止,这是我的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 技术交流群。

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

发布评论

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

评论(2

临风闻羌笛 2024-09-18 16:18:44

如果您希望 /status 转到状态控制器,它应该是资源,而不是命名空间。您可以以大致相同的方式嵌套资源:

map.resource :status do |status|
  status.resources :reports
end

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:

map.resource :status do |status|
  status.resources :reports
end
非要怀念 2024-09-18 16:18:44

命名空间不是资源。

map.resources :statuses do |status|
  status.resources :reports
end

此外,您对 status_path 的调用需要一个 ID。

status_path(:id => @status.id)

status_path(@status)

A namespace isn't a resource.

map.resources :statuses do |status|
  status.resources :reports
end

Also, your call to status_path needs an ID.

status_path(:id => @status.id)

or

status_path(@status)

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