如何基于Rails 3中的slug前缀进行路由?

时间:2012-02-02 22:05:30

标签: ruby-on-rails routes

我需要搜索引擎优化的目的,我需要按州路由,但URL都看起来像一个句子。例如,如果我要卖汽车,我需要:

http://domain.com/new-york-cars-for-sale

我该如何路线?我试过了:

匹配'(:state)-cars-for-sale'=> 'cars #index',:as => :汽车

不行。

1 个答案:

答案 0 :(得分:1)

试试这个:

match '*state-cars-for-sale' => 'cars#index', :as => :cars

然后状态将传递给params [:state]。

See rails routing docs on route-globbing for more details on how to use the * operator in the routes file

相关问题