Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku asset files always empty

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!

like image 594
PatrickEm Avatar asked Sep 01 '13 01:09

PatrickEm


People also ask

Does Heroku provide file storage?

Heroku has an “ephemeral” hard drive, this means that you can write files to disk, but those files will not persist after the application is restarted. By default Active Storage uses a :local storage option, which uses the local file system to store any uploaded files.

Does Heroku remove files?

You can simply delete the old files on your Heroku app using this Heroku repo plugin developed by Heroku . It's very easy to use and you can delete or reset your app in just two lines of code.

Where does Heroku store uploaded files?

Files are uploaded directly to the cloud from your user's browser, without passing through your application. Adding direct uploads to your app allows you to offload the storage of static files from your app. This is crucial on Heroku, because your app's dynos have an ephemeral filesystem.


1 Answers

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.

like image 53
PatrickEm Avatar answered Nov 07 '22 05:11

PatrickEm