2
votes

I'm having trouble with static assets (images and js and stylesheets) not being served on Heroku. Works fine in my local dev env.

Errors look like this:

2011-08-08T02:58:45+00:00 app[web.1]: Started GET "/stylesheets/reset.css" for 98.234.235.21 at 2011-08-07 19:58:45 -0700
2011-08-08T02:58:45+00:00 app[web.1]: 
2011-08-08T02:58:45+00:00 app[web.1]: ActionController::RoutingError (No route matches "/stylesheets/reset.css"):

I'm using:

  • Ruby 1.9.2
  • Rails 3.0.7
  • Heroku with bamboo-mri-1.9.2 and thin webserver. (I followed default basic setup instructions on heroku.com)

I've searched on google / stackoverflow and tried the following with no luck:

  • remove config.ru
  • add use ActionDispatch::Static, "#{Rails.root}/public" to config.ru
  • set config.serve_static_assets = true in staging.rb

Can anyone suggest a fix? Should I be using Cedar instead of Bamboo? Should I be using something else instead of thin?

Thanks!


EDIT: js files are being served, but images and stylesheets are not. I checked that the paths in my links are consistent.

myapp.heroku.com/stylesheets/reset.css - fails myapp.heroku.com/javascripts/jquery.js - succeeds

I also attempted to set the following: config.action_dispatch.x_sendfile_header = nil. This goes along with config.serve_static_assets = true but noticed that Heroku forces these options no matter how you set them. i.e. it does the following during startup:

-----> Detected Rails is not set to serve static_assets
       Installing rails3_serve_static_assets... done
-----> Configure Rails 3 to disable x-sendfile   
       Installing rails3_disable_x_sendfile... done
2

2 Answers

3
votes

The problem turned out to be that the asset files didn't get pushed to heroku (I had a git screwup, not a heroku issue).

Heroku support pointed this out when I contacted them. They promptly replied with a detailed answer, which also included the following comments:

  • Heroku gem is not required to run on Heroku
  • Specify postgres gem in Gemfile; use postgres locally for development in place of sqlite3
  • config.ru: Don't run the dispatcher directly, run the app container
  • dont set x_sendfile_header to nil as this is not properly supported on Rails 3 (this is a Rails 3.1 setting)
0
votes

I am not confident that Heroku is running in the staging environment, I think it's running in the production environment instead and this is why your settings are not being applied.