Rails 4 Static Public index.html [英] Rails 4 Static Public index.html

查看:185
本文介绍了Rails 4 Static Public index.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,这个简单的问题,但我找不到适当的修复任何地方。



我曾经有一个Rails 3.x应用程序运行, public / index.html页面。当然,当我更新到Rails 4时,我的索引页面不再显示。有什么办法让这个功能恢复吗?



我知道我可以创建一个欢迎的#index controller / route并将index.html作为响应。
但是,这是一个不同的文件夹,没有所有公开的图像和css资源,呈现前一个静态页面。



任何提示?您需要使用控制器,但可以简单地将它指向您的现有文件。


$ b

解决方案

$ b

例如in routes.rb

  root:to => 'welcome#index'

然后在Welcome控制器中:

  def索引
render:file => 'public / index.html'
end

或者,您可以设置Apache来投放该文件本身。似乎更容易让Rails做到这一点!


Sorry about the simple question, but I can't find the proper fix anywhere.

I used to have a Rails 3.x app running with a simple landing page on public/index.html. Of course, when I updated to Rails 4, my index page is no longer showing. Is there any way to get that feature back?

I know I can create a welcome#index controller/route and render the index.html as a response. But that goes to a different folder, without all the image and css assets that were on public, rendering the former static page.

Any tips?

解决方案

You need to use a controller, but can simply point it to your existing file.

e.g. in routes.rb

root :to => 'welcome#index'

And then in the Welcome controller:

def index
  render :file => 'public/index.html'
end

Alternatively, you could set up Apache to serve that file itself. Seems easier to let Rails do it though!

这篇关于Rails 4 Static Public index.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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