24
votes

I have deployed a Rails 3.1 application on Heroku Cedar. For some reason my static image assets are not being served:

2011-06-23T18:14:13+00:00 app[web.1]: Started GET "/assets/me_reminder-30f9d1dead32e12238888adbee4b92d3.png" for 98.207.60.248 at 2011-06-23 18:14:13 +0000
2011-06-23T18:14:13+00:00 app[web.1]: Served asset /me_reminder-30f9d1dead32e12238888adbee4b92d3.png - 200 OK (0ms) (pid 1)
2011-06-23T18:14:13+00:00 app[web.1]: cache: [GET /assets/me_reminder-30f9d1dead32e12238888adbee4b92d3.png] miss, store
2011-06-23T18:14:13+00:00 heroku[router]: GET xxxx.herokuapp.com/assets/me_reminder-30f9d1dead32e12238888adbee4b92d3.png dyno=web.1 queue=0 wait=0ms service=35ms status=200 bytes=0

As you can see, it is returning something with 0 bytes. Needless to say, no image shows.

However, all my other static assets (css, javascripts) are being served correctly. Any idea what could be wrong here?

By the way, I have another Rails 3.1 app on heroku which is working just fine, so I don't think it's a problem with sprockets, etc.

Thank you.

4

4 Answers

27
votes

I had the same problem. In config/environments/production.rb file, comment:

config.action_dispatch.x_sendfile_header = "X-Sendfile"

And instead, have:

config.action_dispatch.x_sendfile_header = nil # For Heroku

This is also the recommended way of doing this. As suggested in the Heroku docs.

Works for me.

9
votes

I had the same problem. changing production.rb file configuration to

config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

from

config.action_dispatch.x_sendfile_header = "X-Sendfile"

worked for me. since Heroku uses nginx in front.

1
votes

I had this issue because I was referring to images in the asset pipeline using HTML. Example:

<img src="/assets/hello.jpg" />

The image assets would work locally but not on Heroku. Switching over to using Rails' image_tag view helper solved the issue. Example:

<%= image_tag "hello.jpg" %>
0
votes

If I remember correctly, there can be some unexpected behavior using images in the asset pipeline. To avoid it, you can leave them in public/ just like previous versions of rails.

See the discussion here.