路由匹配到rails中的动态操作

时间:2014-01-29 11:39:14

标签: ruby-on-rails routes

我可以为下面两行写一行路线吗?

match "/article/:id/"  => "articles#redirect"
match "/articles/:id/" => "articles#redirect"

我试过像

这样的东西
  match "/:article_redirect/:id/" => "articles#redirect", :constraints => {:article_redirect => /[article|articles]/}

但它不起作用。

1 个答案:

答案 0 :(得分:1)

我认为你的正则表达不好:试试

match "/:article_redirect/:id/" => "articles#redirect", :constraints => {:article_redirect => /(article|articles)/}

(article|articles)而不是[article|articles]