我的网站上有针对章节和页面的嵌套路线。
resources :sections do
resources :pages
end
这是一个示例网址:
sitename.com/sections/5/pages/22
我不喜欢“部分”这个名称,而更喜欢“章节”。
sitename.com/chapters/5/pages/22
我认为重新命名模型会很复杂,那么我怎样才能轻松地重命名路线呢?
答案 0 :(得分:2)
将您想要的URL段名称作为值传递给path
参数:
resources :sections, :path => :chapters do
resources :pages
end
这导致以下路线:
section_pages GET /chapters/:section_id/pages(.:format) pages#index
POST /chapters/:section_id/pages(.:format) pages#create
new_section_page GET /chapters/:section_id/pages/new(.:format) pages#new
edit_section_page GET /chapters/:section_id/pages/:id/edit(.:format) pages#edit
section_page GET /chapters/:section_id/pages/:id(.:format) pages#show
PUT /chapters/:section_id/pages/:id(.:format) pages#update
DELETE /chapters/:section_id/pages/:id(.:format) pages#destroy
sections GET /chapters(.:format) sections#index
POST /chapters(.:format) sections#create
new_section GET /chapters/new(.:format) sections#new
edit_section GET /chapters/:id/edit(.:format) sections#edit
section GET /chapters/:id(.:format) sections#show
PUT /chapters/:id(.:format) sections#update
DELETE /chapters/:id(.:format) sections#destroy