我有ProjectsController
和SubmissionsController
。我想设置我的路线,以便所有提交都以 projects / 作为前缀但是,在尝试了多种方式后,我似乎无法将其转到工作正常。我可以设置路线很好,它们按预期出来,但找不到我的控制器:
resources :submissions, only: [:index, :show, :create, :new, :edit, :update, :remove, :delete], path: 'projects/submissions'
get 'projects/submissions/:id/remove', to: 'submissions#remove', as: :remove_submission
patch 'projects/submissions/:id/delete', to: 'submissions#delete', as: :delete_submission
但它没有击中我的SubmissionsController
。我的SubmissionsController
和ProjectsController
都位于 app - >中控制器
答案 0 :(得分:2)
请参阅http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing
正确的方法是在scope
块
scope '/projects' do
resources :submissions
end
由于您的范围/projects
与ProjectsController
的路线同名,请务必在ProjectsController路线后声明SubmissionsController
路线> routes.rb 文件。