如何创建一个 Rails 3 路由来匹配所有请求并指向一个资源/页面? [英] How can I create a Rails 3 route that will match all requests and direct to one resource / page?

查看:38
本文介绍了如何创建一个 Rails 3 路由来匹配所有请求并指向一个资源/页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Rails 应用程序 (Rails 3.0),我需要暂时停止使用.虽然这是有效的,但我想创建一个新路由,将所有请求定向到单个静态内容.我设置了一个控制器来为我的静态页面提供服务.

I have a rails app (Rails 3.0) that I need to temporarily take out of service. While this is in effect, I want to create a new route that will direct all requests to a single piece of static content. I have a controller set up to serve my static pages.

我尝试过这样的事情:

match '*' => 'content#holding'

match '*/*' => 'content#holding'

匹配此处描述的通配符路由:Rails 3 路由通配但没有成功.

to match a wildcard route as described here:Rails 3 route globbing without success.

这可能是一个非常简单的答案,但我无法弄清楚.

This is probably a really simple answer, but I couldn't figure it out.

/编辑/忘了提一下,我确实在 routes.rb 文件的最顶部有这个规则.

/EDIT/ Forgot to mention that I did have this rule at the very top of my routes.rb file.

推荐答案

Rails 需要将 url 参数绑定到一个变量,试试这个:

Rails needs to bind the url parameters to a variable, try this:

match '*foo' => 'content#holding'

如果你还想匹配/,使用括号指定foo是可选的:

If you also want to match /, use parenthesis to specify that foo is optional:

match '(*foo)' => 'content#holding'

这篇关于如何创建一个 Rails 3 路由来匹配所有请求并指向一个资源/页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆