5

First, I did a hell of a lot of googling to even get things working on Heroku, but it seems that regardless of whether I let heroku pre-compile my assets during slug compilation, or if I precompile them myself and submit them, either way, my Rails 4 app's application.css is always empty:

$ curl -i http://www.boxscoregeeks.com/assets/application-c712146df692b0fca6c21c0bf1dddcd5.css
HTTP/1.1 200 OK
Content-Type: text/css
Date: Sun, 01 Sep 2013 00:50:10 GMT
Last-Modified: Sun, 01 Sep 2013 00:46:54 GMT
Status: 200 OK
X-Sendfile: /app/public/assets/application-c712146df692b0fca6c21c0bf1dddcd5.css
Content-Length: 0
Connection: keep-alive

To verify, it's fine locally:

$ curl -I http://localhost:3001/assets/application-c712146df692b0fca6c21c0bf1dddcd5.css
HTTP/1.1 200 OK
Last-Modified: Sat, 31 Aug 2013 03:46:55 GMT
Content-Type: text/css
Content-Length: 106237
Connection: keep-alive
Server: thin 1.5.1 codename Straight Razor

My checklist:

  • I have config.serve_static_assets = true in my production.rb file.
  • I have gem 'rails_12factor', group: :production in my Gemfile
  • I did this: heroku labs:enable user-env-compile --app=YOUR_APP. Before I ran that, assets:precompile would not run, despite steps 1 and 2. It would always try to initialize the production database.

Almost all of my googling tells me to do these things above, but here I am still with an empty applicaiton.css file. Any help would be great.

Thanks!

PatrickEm
  • 346
  • 2
  • 10
  • Also in `production.rb` make sure to enable `config.assets.precompile += %w( search.js )`. Do NOT use `config.assets.precompile = ['*.js', '*.css']`, as other threads may have suggested. – ahnbizcad Sep 06 '14 at 22:13
  • Once you do, ALSO make sure to run `RAILS_ENV=production rake assets:precompile`. Then commit and push. – ahnbizcad Sep 06 '14 at 22:15

1 Answers1

6

I found my own answer to this question.

The app in question is one that I upgraded from rails 3. So I built and deployed an empty new rails 4 app (and this worked). By diffing the production.rb files, I noticed that the non-working app had a line like this in it:

# Specifies the header that your server uses for sending files
# (comment out if your front-end server doesn't support this)
config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx

This config line is commented out in the new rails 4 app. And the Heroku docs recommend this:

config.action_dispatch.x_sendfile_header = nil # For Heroku

When I changed this, everything worked as expected. This did not seem to matter when the app was running on Cedar in rails 3.

PatrickEm
  • 346
  • 2
  • 10
  • Oh my, you have no idea how awesome this was. Fixed my insane issues too! – tvalent2 Sep 01 '14 at 22:30
  • You have done a great service for the world, sir PatrickEm. *pins cyber medal* – ahnbizcad Sep 06 '14 at 22:17
  • You're a life saver! Thank you for helping debug this stupid error. For some reason, the rails_12factor gem doesn't overwrite this setting. – jlev Apr 01 '16 at 19:18