solution to fix issue where heroku doesn't serve css, images and static files
Heroku is cool, but it took me forever to figure out why it wasn’t serving my css and images. It was basically returning 404 for any file in the public directory.
I just got errors like this:
ActionController::RoutingError (No route matches "/javascripts/base_packaged.js" with {:method=>:get, :canvas=>false}):
/home/heroku_rack/lib/static_assets.rb:9:in `call'
Given that the app that I’m trying on Heroku is also running perfectly well in production on slicehost, this was pretty confusing.
After thinking it through and looking at Rack::Static, I updated my config.ru (the rackup file) according to lifo’s instructions here, and suddenly everything worked. I then intentionally changed it back and verified that this was indeed the issue.
I changed it from this:
1 2 3 4 5 6 7 8 9 |
# Doesn't work with heroku # Require your environment file to bootstrap Rails require File.dirname(__FILE__) + '/config/environment' # Dispatch the request run ActionController::Dispatcher.new |
to this:
1 2 3 4 5 6 7 8 |
# works with heroku require "config/environment" use Rails::Rack::LogTailer use Rails::Rack::Static run ActionController::Dispatcher.new |
Hopefully this helps someone else.


Recent comments
1 year 23 weeks ago
1 year 23 weeks ago
1 year 25 weeks ago
1 year 27 weeks ago
1 year 42 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 46 weeks ago
1 year 48 weeks ago