Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Precompiled CSS not found in Rails 3.1 production mode

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
like image 444
Kiran Ryali Avatar asked Oct 12 '11 06:10

Kiran Ryali


2 Answers

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)

like image 57
Rodrigo_at_Ximera Avatar answered Oct 21 '22 06:10

Rodrigo_at_Ximera


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.

like image 30
Kiran Ryali Avatar answered Oct 21 '22 04:10

Kiran Ryali