Ruby on rails and active_admin assets on Heroku

If you are using heroku you probably ran into some issues with rake assets:precompile. When using active admin bringing it’s assets into your app can also be quite tricky.

The method of precompiling your assets yourself and adding them to your git repository works for sure but it isn’t really best practice.

Another way to get the needed assets to be compiled is as follows:

  1. Configure the config.assets.initialize_on_precompile = false if you don’t have it already (refer to the heroku faq).
  2. Modifiy config/application.rb and require the :assets group with bundler.
  3. Add the line config.assets.precompile += %w( active_admin.css active_admin/print.css active_admin.js ) also to your config/application.rb not the config/environments/production.rb.

Be sure to write active_admin.css and not active_admin.css.scss in the assets.precompile line!

config/application.rb
...
if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  # Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  Bundler.require(:default, :assets, Rails.env)
end

module Bildungsnetz
  class Application < Rails::Application
    ...
    # Enable the asset pipeline
    config.assets.enabled = true

    # Disable application initialize on precompile (heroku faq: fixes database access error on precompile)
    config.assets.initialize_on_precompile = false

    # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
    config.assets.precompile += %w( active_admin.css active_admin/print.css active_admin.js )
    ...
  end
end
Jens Grassel Written by:

Solving problems and burning chrome for fun and profit.