activeadmin heroku stylesheet config issue with partial fix activeadmin heroku stylesheet config issue with partial fix heroku heroku

activeadmin heroku stylesheet config issue with partial fix


I was finally able to resolve this issue. In case someone else runs into this problem, I thought I would document the steps that I took to resolve it.

I ran my application locally in production mode (RAILS_ENV=production rails s) and was able to duplicate the error that I received on Heroku on my local machine.

I copied my active_admin.css.scss and active_admin.js to the /vendor/assets directory. Since y app kept telling me that it was missing active_admin/mixins I also copied the entire active_admin directory in assets to the vendor/assets directory. I am not sure if this is necessary or not.

From a Heroku perspective, I've been told, but can not confirm, that production.rb is not read during the precompile so all settings need to be defined in application.rb. So, I made sure that I had the following settings in application.rb -

#Added to fix devise/active admin issue ?config.assets.initialize_on_precompile = false# Precompile additional assets. Defaults to [application.js, application.css, non-JS/CSS]config.assets.precompile += ['active_admin.css.scss', 'active_admin.js'] 

I found most of above tips around the net (on stackoverflow, heroku, github, etc.). The part that I did not see was the need to make change Bundler.require in application.rb from:

Bundler.require(*Rails.groups(:assets => %w(development test)))

to:

Bundler.require(:default, :assets, Rails.env)

Once I made those changes then I could push the code onto Heroku and let it precompile the assets for me. I hope that this can help someone save some time in resolving this issue.


You're on the right track, in letting Heroku compile assets for you. That makes things easiest.

To include additional files in the precompiler manifest, use something like this in your application config (either config/application.rb or config/environments/production.rb):

# Precompile additional assets. Defaults to [application.js, application.css, non-JS/CSS]config.assets.precompile += ['active_admin.css', 'active_admin/print.css', 'active_admin.js']


The ActiveAdmin github wiki addresses this issue specifically: https://github.com/gregbell/active_admin/wiki/Heroku-Cedar-deployment-with-the-Asset-Pipeline

Here's what it says at the time of writing:


  1. Try adding the AA assets to the precompile list in application.rb (NOTE: you CANNOT add them in production.rb, Heroku does NOT read production.rb during precompile!)

    # config/application.rbconfig.assets.precompile += %w( active_admin.css active_admin.js active_admin/print.css )
  2. Try placing active_admin.css.scss and active_admin.js in vendor/assets instead of app/assets. This prevents inadvertent inclusion of AA assets when you use the sprockets directive require_tree . This is the default sprockets directive in application.css for a new rails app and is why many people get confused about AA assets being required on all parts of their site. Putting the AA assets in vendor/assets prevents this problem but you could just as well put it in a subdirectory of app/assets and avoid using the require_tree directive (opting for require_directory instead).

  3. Make sure sass-rails is available when precompiling. This entails making sure that either the assets group is required during precompile or making sass-rails available in all gem groups. Often upgrades from older versions of Rails will not have the correct Bundler require statement so this is important to check if you didn't start your project on Rails 3.1+. If you can run bundle exec rake assets:precompile RAILS_ENV=production on your machine without errors and with a fake production db configured then you're good.

  4. Set up heroku-specific config as directed in their FAQ about deploying using the asset pipeline:

    # config/application.rb - NOT production.rbconfig.assets.initialize_on_precompile = false