Rails 4 & Heroku: The Asset Pipeline Quandary
Let’s find those pesky missing assets from your recently-deployed web app.
So you’re riding Rails 4 and are throwing your recently-built social/mobile/local app on Heroku so you can have something live to demo for tomorrow’s pitch in front of Marc & Ben? But shit — none of your assets seem to be propagating properly. Not to worry though, there are just a few new adjustments for Rails 4 apps that need to be completed in order to get things back in tip top shape. Before I go through these adjustments, I’m going to assume you’ve gone through the basics of deploying your app on Heroku. Once you’ve got that sorted, have a shout at the below if your assets are still missing.
Add the following gem to your Gemfile
gem ‘rails_12factor’, group: :production
Add the following to /config/production.rb
config.serve_static_assets = true
config.action_dispatch.x_sendfile_header = ‘X-Accel-Redirect’
config.assets.compile = true
Feel free to push everything to Heroku and refresh. If things still aren’t sorted, keep on reading.
Enable the following experimental feature via the Heroku command line interface:
heroku labs:enable user-env-compile -a yourapp
Push to Heroku again and have a shout. Still broken? Try precompiling your assets locally then committing (again via the Heroku CLI):
heroku run rake assets:precompile
Note: this command will have to be run after any changes to the asset pipeline are made.
Hope this helps — feel free to ping me with questions on Twitter (@jcap49).