Rails:自定义路由嵌套自定义路由?

时间:2013-10-22 03:12:19

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 routes

我可以在自定义路线中嵌套自定义路线吗?

localhost:3000/prof/3

match 'prof/:id' => 'professionals#show', :as => :prof

我想做更多自定义路线:

localhost:3000/prof/3/services/2

现在我有这个:

resources :professionals do
  resources :services, :defaults => { :servicable => 'professional' }
end

这给了我类似的东西:

/professionals/:professional_id/services/:id

我还在学习rails方法。

1 个答案:

答案 0 :(得分:2)

您只需为资源指定path选项即可将其放置在特定位置。

resources :professionals, path: '/prof' do
  resources :services, :defaults => { :servicable => 'professional' }
end