Rails路由:Scoped控制器

时间:2014-02-06 11:23:04

标签: ruby-on-rails routing

我有ProjectsControllerSubmissionsController。我想设置我的路线,以便所有提交都以 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。我的SubmissionsControllerProjectsController都位于 app - >中控制器

1 个答案:

答案 0 :(得分:2)

请参阅http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing

正确的方法是在scope

中编写路线
scope '/projects' do
  resources :submissions
end

由于您的范围/projectsProjectsController的路线同名,请务必在ProjectsController路线后声明SubmissionsController路线> routes.rb 文件。