我有一个名为Contributor
的模型,它也充当其他几个模型的名称空间,例如Contributor::Alias
和Contributor::Reassignment
。我想使用包括贡献者ID像这样一个URL:Rails 3:获取名称空间模型的ID
/contributors/1/reassignments/new
但我得到这个错误:
No route matches [GET] "/contributors/1/reassignments/new"
我routes.rb
文件包括:
namespace :contributor do
resources :reassignments
end
resources :contributors
我也尝试过:
resources :contributors do
resources :reassignments
end
这导致不同的错误:
uninitialized constant ReassignmentsController
任何想法如何处理这个?也许我不应该使用也作为模型的命名空间?我没有在任何教程中看到过这一点,尽管看起来这可能是可能的。
UPDATE:
你如何处理深层嵌套的命名空间模型,如:
resources :contributors do
resources :reassignments, :module => "contributor" do
resources :approvals, :module => "reassignment"
end
end
使用这种方法,我得到的错误:
No route matches {:action=>"create", :controller=>"contributor/reassignment/approvals"}
我的控制器,目录不会具有以下结构:
contributor ->
reassignment ->
approvals_controller.rb
这似乎与第一个错误有关,但也许它是新东西。
非常好!我对模块路由不熟悉,但它在这里做了诀窍。如果你有时间,我有一个相关的问题。我有另一个命名空间/模型嵌套在第二层,我有类似的路由问题。我已经更新了我的问题,如果你有机会,你会看看吗? – nullnullnull 2013-02-28 03:01:32
您的控制器在approvals_controller.rb中如何定义?是参与者::重新分配:: ApprovalsController还是smth其他?这可能是原因。 – moonfly 2013-02-28 03:23:11
它是'Contributor :: Reassignment :: ApprovalsController'。更新后仍然没有运气,但我会继续尝试,并让我知道如果我找到解决方案。如果您有任何其他建议,那也将不胜感激。 – nullnullnull 2013-02-28 03:30:46