有没有办法可以自动路由 - 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
但是如果可能的话,需要反向并自动完成。
答案 0 :(得分:0)
也许您真正需要的是重定向:
match "/pages/1", :to => redirect("/home")
match "/pages/:id", :to => redirect("/contact-us")
请注意,订单很重要 - “Rails路由按照指定的顺序进行匹配”(参见http://edgeguides.rubyonrails.org/routing.html)