0

我对rails中的路线有疑问。

在我的新项目中,我的模型名称为

  1. Country
  2. States
  3. Category
  4. Subcategory
  5. advertisements

我想生成如下路线

1. /en
2. /en/advertisements
3. /en/indiana
4. /en/indiana/advertisements
5. /en/indiana/cars
6. /en/indiana/cars/advertisements
7. /en/indiana/cars/bmw/advertisements
8. /en/cars/advertisements

前任 :-

  en is country locale
  indiana is state
  cars is category
  bmw is sub category

这是我在 routes.rb 中的路由声明

  scope ":language" do <br />
      &nbsp;&nbsp;&nbsp;&nbsp;scope "(:state)" do <br />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scope "(:main_category)" do <br />
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      scope "(:category)" do <br />
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;    resources :advertisements <br />
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;    match "search" => "advertisements#index"
       <br />  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;end<br />
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br />
  &nbsp;&nbsp;&nbsp;&nbsp;  end<br />
  end  <br />

如果 url 是“/en/indiana/cars/bmw/advertisements”,上述路线可以正常工作

现在我想要“/en/cars/advertisements”“/en/cars/advertisements”的路线,然后它将分配 en 到语言和汽车状态

我如何声明此“/en/cars/advertisements”的路线,

请帮帮我

提前致谢

4

1 回答 1

0

使用匹配路由。我认为这可能会解决您的问题。

   match '/:language/:category/advertisements' => 'controller#action_name'
于 2013-02-15T06:22:40.357 回答