Ruby on rails and active_admin assets on Heroku
2012-06-11
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:
- Configure the
config.assets.initialize_on_precompile = false
if you don’t have it already (refer to the heroku faq). - Modifiy
config/application.rb
and require the:assets
group with bundler. - Add the line
config.assets.precompile += %w( active_admin.css active_admin/print.css active_admin.js )
also to yourconfig/application.rb
not theconfig/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