Precompiled CSS not found in Rails 3.1 production mode
Asked Answered
P

3

18

When I start up rails in production mode, it precompiles all the assets but is unable to serve the application.css asset. I looked in public/assets and the precompiled application.css exists.

However, I get a 404 whenever I try to access it from the page.

These are the instructions I use to launch the server, if that may help at all.

RAILS_ENV=production bundle exec rake assets:clean
RAILS_ENV=production bundle exec rake assets:precompile
rails -e production
Paquette answered 12/10, 2011 at 6:19 Comment(2)
I don't use Rails 3.1, but isn't the assets folder in the root of your application, not in the public folder? Forgive me if this is wrong.Binturong
this is wrong, it is in the public folderPaquette
V
34

If you want Rails to serve the static assets you have add the following line to your production.rb:

config.serve_static_assets = true

I understand it's better to allow apache or nginx to serve them, but this works if you are using a rails standalone server (or at least it works with thin)

Vanda answered 30/12, 2011 at 14:48 Comment(0)
P
3

So turns out that rails isn't responsible for serving the static assets that it precompiles. You must configure the web server you use (i.e. nginx) to serve those static assets for you instead of rails. I wish this was much clearer on the docs.

Paquette answered 16/10, 2011 at 1:0 Comment(1)
can u provide a link on how to configure the server for the same?Communicable
J
0

Could you please confirm that you have

<%= stylesheet_link_tag "application" %>

in the head segment in your application layout instead of something like:

<link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" />

This makes sure the precompiled application-xxx.css will be included.

Jawbreaker answered 12/10, 2011 at 9:38 Comment(2)
Where is your original appliation.css located? Is it in /app/assets/stylesheets/application.css? Also, what does the html source look like in terms of the stylesheet link tag? Does it reference application.css or the precompiled application-xxx.css?Jawbreaker
The original application.css is in /app/assets/stylesheets/. The html source references the precompiled application-xxx.cssPaquette

© 2022 - 2024 — McMap. All rights reserved.