Skip to content

Instantly share code, notes, and snippets.

@parndt
Last active May 29, 2019 11:59
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parndt/11381872 to your computer and use it in GitHub Desktop.
Save parndt/11381872 to your computer and use it in GitHub Desktop.
Asset precompilation from an Engine's initializer
### RAILS 4.1
# Doesn't work, due to the error:
# Asset filtered out and will not be served: add
# `Rails.application.config.assets.precompile += %w( refinery/refinery.css )`
# to `config/initializers/assets.rb` and restart your server
class MyEngine < Rails::Engine
# set the manifests and assets to be precompiled
initializer "refinery.assets.precompile" do |app|
app.config.assets.precompile += %w(
refinery/*
refinery/icons/*
wymeditor/lang/*
wymeditor/skins/refinery/*
wymeditor/skins/refinery/**/*
modernizr-min.js
admin.js
)
end
end
# Works:
class MyEngine < Rails::Engine
# set the manifests and assets to be precompiled
config.to_prepare do
Rails.application.config.assets.precompile += %w(
refinery/*
refinery/icons/*
wymeditor/lang/*
wymeditor/skins/refinery/*
wymeditor/skins/refinery/**/*
modernizr-min.js
admin.js
)
end
end
@terenceponce
Copy link

Thanks for this. I should point out that you should only include the manifest if you're using a manifest to load the rest of the stylesheets/javascripts. I didn't get it right the first because I used /* instead of including the manifest explicitly. That resulted in loading everything with no regards to the load order specified in the manifest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment