如何使用Rails提供静态html页面? [英] How to serve static html pages with Rails?

查看:226
本文介绍了如何使用Rails提供静态html页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的公共文件夹的树:

  -public 
-docs
-intro
introduction.html
-css
some.css
index.html

Index.html文件是:

 < link rel =stylesheethref =css / some.csstype =text / css/> 
部分文字
< li> href =intro / introduction.html>< em>简介< / em>< / a>< / li&

当我打开索引页面css没有加载,当我试图点击链接路由错误。我知道静态页面不知道在哪里寻找css和其他html页面。



我只想要静态页面没有任何路由和控制器,nginx。



任何想法?

解决方案

(页面或不是)通过公共目录。因为Kirka121说rails不是真正建立这个目的,但仍然可以使用它。



在开发环境中,它应该只是工作,以服务任何文件,你有公共,生产环境,你可能需要配置任何服务器,你用来为他们服务 - 但这应该被其正常的设置覆盖,如果不是它的设置错了。



默认的rails公共文件夹可以直接通过访问在项目的根。



到你的代码,相对链接/ url似乎是问题。



对于你的文件夹结构和示例,这将是:

p>

 < link rel =stylesheethref =/ docs / css / some.csstype =text / css > 
部分文字
< li>< a href =/ docs / intro / introduction.html>< em>简介< / em>< / a& li>


I have Rails application with documentation which is static html pages in the /public folder.

The tree of my public folder:

-public
  -docs
    -intro
      introduction.html
    -css
      some.css
    index.html 

Index.html file is:

<link rel="stylesheet" href="css/some.css" type="text/css" />
Some of the text
<li>href="intro/introduction.html"><em>Introduction</em></a></li> 

When I open index page css isn't loaded, and when I try to click on link it says routing error. As I understood static pages don't know where to look for css and other html pages.

I just want static pages without any routes and controllers, nginx.

Any ideas?

解决方案

Its perfectly valid to serve static files (pages or not) via the public directory. As Kirka121 said rails is not really built for this purpose but can still work with it.

In development environment it should just work to serve whatever files you have in public, for production environment you might need to configure whatever server you use to serve them - but this should be covered by its normal setup anyway, if not its set up wrong.

So by default the rails public folder can directly by accessed at the root of the project.

As far as your code goes the relative links/urls seem to be the issue. Its generally better to use absolute paths for everything not to confuse anything, which leads to very hard to find bugs.

With your folder structure and example this would be:

<link rel="stylesheet" href="/docs/css/some.css" type="text/css" />
Some of the text
<li><a href="/docs/intro/introduction.html"><em>Introduction</em></a></li> 

这篇关于如何使用Rails提供静态html页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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