Rails 3.1 Asset Pipeline Not Serving Up Images
Posted on 10/04/2011
New features were developed, tests were passing, and everything was running great in the local dev environment.
Then I deployed to the staging server.
WTF? None of the image assets were displaying. The user-uploaded images on S3 were fine, but nothing under assets/images
was rendering. It was midnight with a client demo the next morning. I was ready to pull my hair out.
I checked the logs. No errors. The server seemed to be serving up image assets w/o a problem. The logs lied and I knew better.
My first thought; this is what I get for saying I didn't understand people's complaints about the asset pipeline. My second thought; precompile. I rm'd the public/assets
directory and ran the precompile rake task. No dice. Still no images.
The staging server was running on Bluebox, so I had hit them up in the support chat. We both poked around and tried a few things, but nothing was working. Then finally one of the support guys found it.
In the staging environment file, this line needed to be changed since we were using Nginx:
config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx
Once that was changed and the app was restarted, everything worked as expected.