Ruby on Rails - 静态页面作为起始页面
我正在 RoR 中开发一个应用程序,它有静态和动态部分。静态部分放置在应用程序的 public/ 文件夹中。现在,如果我的公共文件夹中有一个index.html,那么我将无法使用在routes.rb中配置的路由。像 map.connect /:controller/:action 这样的默认配置将不会如果我有一个index.html就可以使用。所以我删除了索引 html。
现在我的 public/ 文件夹中有一个静态页面 startpage.html ,它必须是应用程序的起始页面。其中有其他静态/动态页面的链接。
RoR 应用程序托管在 apache 中,我尝试通过添加 DirectoryIndex 参数来配置虚拟主机配置,以便当对该站点发出请求时,它会将其定向到 startpage.html 但仍然会将我带到默认控制器我已在routes.rb中使用map.root指定
我不想添加虚拟控制器和操作并创建一个具有起始页的视图并配置routes.rb以将其用作根。我在这里想做的是
基本上 startpage.html 应该是我在应用程序中的第一页,作为 public/ 文件夹中的静态页面。然后,这将链接到其他页面和控制器/操作。
在这里,我无法将 apache 重定向到 html 页面,而不是将控制传递给 Rails 应用程序。目录列表也可以通过使用选项索引来启用,但仍然没有变化。
有人指点一下吗?
I am developing an app in RoR which has static and dynamic parts. The static portion is placed in the public/ folder of the app. Now if i have an index.html in my public folder then i will not be able to use the routes configured in my routes.rb The default configurations like map.connect /:controller/:action will not be usable if i have an index.html. So i removed the index html.
Now i have a static page startpage.html in my public/ folder which has to be the starting page of the app. And the i have links in it for other static/dynamic pages.
The RoR app is hosted in apache and i tried to configure the Virtual Host configuration by adding the DirectoryIndex param so that when ever a request comes for the site it will direct it to the startpage.html but still it takes me to the default controller that i have specified in routes.rb with map.root
I dont want to add a dummy controller and action and create a view which has the startpage and configure routes.rb to use it as the root. What i am looking to do here is
Basically startpage.html should be my first page in the app served as a static page from the public/ folder. This will then have links to other pages and controllers/actions
Here i am not able to apache to redirect to the html page instead of passing on the control to rails application. Directory listing is also enabled by using Options Indexes but still no change.
Any pointers anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是不正确的。问题的解决方案是将
startpage.html
重命名为index.html
,这将导致对/
的请求由提供服务index.html
,任何对/:controller/:action
的请求都将传递到 Rails 路由引擎。Apache 将首先提供它可以在
public
目录中找到的任何内容。如果它不可用,则会将请求传递给 Rails(这就是页面缓存的工作原理)。有了
index.html
就位,您就不需要map.root
,因为它永远不会被请求(记住,Apache 服务/
与 <代码>index.html)。而且您也不需要任何特殊指令。This is incorrect. The solution of your problem is to rename
startpage.html
toindex.html
, which will cause requests for/
to be served byindex.html
, and any requests for/:controller/:action
will be passed along to Rails Routing engine.Apache will first serve anything it can find in the
public
directory. If it's not available, then it passes the request off to Rails (this is how page caching works).With
index.html
in place, you do not needmap.root
, as it will never get requested (remember, Apache serves/
withindex.html
). And you don't need any special directives either.您可以将 URL 从 index.html 重写为 startpage.html
You can made a URL rewrite from index.html to your startpage.html