Fixing Missing Assets With Rails 4 on Heroku
Patrick Reagan, Former Development Director
I ran into a strange issue when deploying my Rails 4 application to Heroku's Cedar stack. Every time I pulled up the home page the content would display, but styles were completely missing. If I used heroku config:set to change both RAILS_ENV and RACK_ENV to development, assets would be served again as expected.
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError: hella-tite.css isn't precompiled
My problem was twofold:
- The application was using a stylesheet other than the default application.css
- This file had not been precompiled
Setting the environment to development just masked the issue by compiling assets on the fly — not a good idea for a production environment.
Making it Work
In this case, identifying the problem was the hard part — the fix is easy. Make sure you're using the rails_12factor gem (for logging and asset serving):
group :production do
Then add the asset(s) to the precompilation list:
config.assets.precompile += [
Deploying the application after these changes will now serve up the correct stylesheet.