1

有没有办法可以将 - http://localhost:3000/pages/1路由到http://localhost:3000/home以及我网站中的所有其他页面,即 - http://localhost:3000/pages/4自动到http://localhost:3000/contact-us

我可以用另一种方式做到这一点 -

match "/home" => 'pages#show', :id => 1
match "/cars-for-sale" => 'pages#show', :id => 1
match "/contact-us" => 'pages#show', :id => 4

但如果可能,需要反向并自动执行此操作。

4

1 回答 1

0

也许您真正需要的是重定向:

match "/pages/1", :to => redirect("/home")
match "/pages/:id", :to => redirect("/contact-us")

请注意,顺序很重要 - “Rails 路线按照指定的顺序匹配”(请参阅​​ http://edgeguides.rubyonrails.org/routing.html

于 2011-12-02T13:42:06.247 回答