Rails,将许多命名路线路由到一个操作
有没有一种更简单的写法:
map.old_site_cusom_packages '/customs_packages_options.html', :controller => :public, :action => :redirect_to_home
map.old_corporate '/corporate.html', :controller => :public, :action => :redirect_to_home
map.old_track '/track.html', :controller => :public, :action => :redirect_to_home
map.old_links '/links.html', :controller => :public, :action => :redirect_to_home
map.old_contact '/contact.html', :controller => :public, :action => :redirect_to_home
我想将许多命名路由发送到一个控制器上的一个操作,我确保旧站点重定向到正确页面时留下的网址。
干杯。
Is there a simpler way of writing this:
map.old_site_cusom_packages '/customs_packages_options.html', :controller => :public, :action => :redirect_to_home
map.old_corporate '/corporate.html', :controller => :public, :action => :redirect_to_home
map.old_track '/track.html', :controller => :public, :action => :redirect_to_home
map.old_links '/links.html', :controller => :public, :action => :redirect_to_home
map.old_contact '/contact.html', :controller => :public, :action => :redirect_to_home
I want to send many named routes to one action on one controller, I'm making sure url's left over from an old site redirect to the correct pages.
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
with_options
方法:Use the
with_options
method:您始终可以使用正则表达式编写多用途路由来捕获详细信息:
这应该捕获特定页面并相应地重定向它们。更可靠的解决方案是在数据库中设置某种查找表,在提供任何内容或 404 类型页面之前检查该表。
编辑:对于命名路由,这是一个简单的更改:
在大多数情况下,可以使用首先列出的单个旧路由来重写旧路由。最好使路由表尽可能精简。第二种方法更像是尝试弥合旧路线的拐杖。
You can always write a multi-purpose route with a regular expression to capture the details:
That should capture specific pages and redirect them accordingly. A more robust solution is to have some kind of lookup table in a database that is checked before serving any content or 404-type pages.
Edit: For named routes, it's an easy alteration:
In most cases the old routes can be rewritten using the singular legacy route listed first. It's also best to keep the routing table as trim as possible. The second method is more of a crutch to try and bridge the old routes.