创建仅包含参数的rails路由

时间:2014-07-22 13:34:22

标签: ruby-on-rails routes

我想创建一个只有参数的rails路由。例如:

match '/:taxonomy/:taxon/(:tag)' => 'shop#index', :as => 'shop'

目前,我正在为taxonomy的每个可能值创建单独的rails路由。 E.g。

match '/jewellery/:taxon/(:tag)' => 'shop#index', :as => 'shop'
match '/bags-and-wallets/:taxon/(:tag)' => 'shop#index', :as => 'shop'
match '/mens-jewellery/:taxon/(:tag)' => 'shop#index', :as => 'shop'
match '/mens-accessories/:taxon/(:tag)' => 'shop#index', :as => 'shop'

如果我使用/:taxonomy/:taxon/(:tag),其他一些网页也会开始路由到shop_controller

这可能吗?可能通过设置taxonomy参数的允许值?

1 个答案:

答案 0 :(得分:0)

只需将您的only-parameters-matcher放在所有其他参数之后。 即确保带参数的路由是路由文件中的最后一条路径。

相关问题