Reputation: 567
I have done everything:
Gemfile:
gem 'rails_12factor', group: :production
config/environments/production.rb
config.serve_static_assets = true
config/application.rb
config.assets.precompile += %w( *.css *.js )
I have my js and css files under vendor/assets/. When I deploy to heroku everything looks good:
Running: rake assets:precompile
Asset precompilation completed (310.44s)
When I see application-5c84e59d83c00fd13fb659edc18db24a.js and application-cb9661f49811aa5c8d103e83ee8747b2.css, them are empty
What am I doing wrong ?
I have read:
Heroku does NOT compile files under assets pipelines in Rails 4
Tried several fixes: Heroku/Rails 4 Assets Precompile Error
Upvotes: 0
Views: 1147
Reputation: 9193
You can solve this by explicitly adding the following to application.rb
# config/application.rb
config.assets.paths << Rails.root.join('vendor', 'assets')
It seems that although Rails knows exactly what it wants, Heroku needs reminding to include the assets folder as part of the assets paths.
Upvotes: 0
Reputation: 346
I believe I found the root cause issue. I chose to post it as a new answer because it is separate from the work-around I posted above.
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.
Upvotes: 1
Reputation: 346
This is not the "real" solution, but Heroku will compile assets at runtime. See this guide.
Of course, by default in production, your view renders any asset_paths generated through helpers (e.g. image_tag() or styleheet_link_tag(), or asset_path() within your SASS, etc) with a digest, which would normally grab the appropriate precompiled file.
But this is broken, so you can turn this off, and let rails compile assets at runtime. This is obviously much less performant, but if your only goal is to get your site working right now, this should work.
In production.rb
:
config.assets.digest = false
Then your stylesheet link should resolve to something like /assets/application.css, which should work (it did in my app). But, again, this isn't the real solution but rather a work-around. If you make any traction on the actual root cause, let me know.
Upvotes: 0