Skip to content Skip to sidebar Skip to footer

How To Serve Static Html Pages With Rails?

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 -

Solution 1:

All the public folder content is accessible via "/"

<link rel="stylesheet" href="/docs/css/some.css"type="text/css" />

You can use high_voltage gem to generate static_pages

Solution 2:

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:

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

Post a Comment for "How To Serve Static Html Pages With Rails?"