路由到页面名称
有没有一种方法可以将 - 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
我可以使用 -但需要反向执行此
is there a way i could route - http://localhost:3000/pages/1 to http://localhost:3000/home and all the other pages in my site i.e. - http://localhost:3000/pages/4 to http://localhost:3000/contact-us automatically?
I can do this the other way around using -
match "/home" => 'pages#show', :id => 1
match "/cars-for-sale" => 'pages#show', :id => 1
match "/contact-us" => 'pages#show', :id => 4
but need to do this in revers and automatically if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您真正需要的是重定向:
请注意,顺序很重要 - “Rails 路由按照指定的顺序进行匹配”(请参阅 http://edgeguides.rubyonrails.org/routing.html)
Perhaps what you really need is a redirect:
Note, that the order is significant - "Rails routes are matched in the order they are specified" (see http://edgeguides.rubyonrails.org/routing.html)