簡體   English   中英

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

會生成以下網址幫助器:

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幫助器(索引,新建,編輯,顯示等)而不僅僅是顯示路徑。

不必巢那么深。

我個人僅深入兩層,這使得維護起來更容易。

但這並不能回答問題。 也許是的。

隨着您的設置。 您可以執行以下操作:

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

這為您提供了module_exams_path作為幫助器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM