1

有没有一种方法我可以路由 - http://localhost:3000/pages/1http://localhost:3000/home和我的网站中的所有其他页面,即 - http://localhost:3000/pages/4http://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

也许你真正需要的是一个重定向:

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

注意,该订单是显著 - “Rails的路线在他们指定的顺序进行匹配”(见http://edgeguides.rubyonrails.org/routing.html