我有一个名为 的模型Contributor
,它也充当其他几个模型的命名空间,例如Contributor::Alias
和Contributor::Reassignment
。我想使用包含贡献者 ID 的 URL,如下所示:
/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
知道如何解决这个问题吗?也许我不应该使用同时充当模型的命名空间?我没有在任何教程中看到这样做,尽管它似乎是可能的。
更新:
如何处理深度嵌套的命名空间模型,例如:
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
这似乎与第一个错误有关,但也许是新事物。