使用多态嵌套资源时,我遇到了inherited_resources 的问题,其父资源之一是命名空间控制器。这是一个抽象的例子:
# routes.rb
resources :tasks do
resources :comments
end
namespace :admin do
resources :projects do
resources :comments
end
end
# comments_controller.rb
class CommentsController < InheritedResources::Base
belongs_to :projects, :tasks, :polymorphic => true
end
当我访问/admin/projects/1/comments
时,我收到此错误:
ActionController::RoutingError at /admin/projects/1/comments
uninitialized constant Admin::CommentsController
Admin::CommentsController
现在如果我定义控制器controllers/admin
为/tasks/1/comments
有没有办法解决这个问题?