17andLearning
17andLearning

Reputation: 477

Relative linking (RoR)

I have some static error pages under /public, in which I have linked a stylesheet called errors.min.css in the following manner:

<link rel="stylesheet" href="errors.min.css">

However, while I'm on a path except the root (/abc/non-existent-url), the pages don't render properly as the CSS file is not found (since its under a different path now.) I tried setting the URL to:

/public/errors.min.css

but it doesn't seem to work. Is there something I can do (except making the CSS inline, which I don't want to do)?

Upvotes: 1

Views: 47

Answers (1)

knownasilya
knownasilya

Reputation: 6143

You should not use static stylsheet linking in Rails. Try the following:

<%= stylesheet_link_tag "errors.min.css" %>

This assumes that the stylesheet is in the app/assets/stylesheets/ directory.

Also your static pages would have to end with .html.erb for this to work.


P.S. Static pages should also be made using a controller. See this tutorial on static pages.

Upvotes: 1

Related Questions