Rails 嵌套资源和 url 助手 - 如何缩短

Rails nested resources and url helpers - how to shorten

在我的 routes.rb 文件中,我有以下资源:

resources :educations do
  resources :semesters do
    resources :module_assignments do
      resources :module_exams do
        resources :module_marks
      end
    end
  end
end

生成这个 url 帮助器:

logonname_module_assignment_module_exams_path   GET /:student/module_assignments/:module_assignment_id/module_exams(.:format)   module_exams#index

有什么办法可以缩短这个时间吗?它应该重定向到同一个控制器和同一个动作。而不是

logonname_module_assignment_module_exams_path

我更喜欢

module_exams_path

有办法解决吗?我想要所有这样的 url-helpers(索引、新建、编辑、显示等),而不仅仅是显示路径。

没有这么深的嵌套。

我个人只深入到两个深度,这样更容易维护。

但这并没有回答问题。或者也许是。

根据您的设置。你可以这样做:

match '/:student/module_assignments/:module_assignment_id/module_exams(.:format)' => 'module_exams#index', :as => :module_exams

这给你 module_exams_path 作为帮手。