Today I finally finished the rails 3.1 upgrade for our open source CMS Alchemy.
An issue I ran into was, that while deploying, the assets from inside the engine weren’t precompiled.
I solved it by telling the main app to also precompile Alchemys assets:
# lib/alchemy/engine.rb
module Alchemy
class Engine < Rails::Engine
# Config defaults
config.mount_at = '/'
# Enabling assets precompiling under rails 3.1
if Rails.version >= '3.1'
initializer :assets do |config|
Rails.application.config.assets.precompile += %w( alchemy/alchemy.js alchemy/alchemy.css alchemy/print.css )
end
end
# Check the gem config
initializer "check config" do |app|
# make sure mount_at ends with trailing slash
config.mount_at += '/' unless config.mount_at.last == '/'
end
initializer :flash_cookie do |config|
config.middleware.insert_after(
'ActionDispatch::Cookies',
Alchemy::Middleware::FlashSessionCookie,
::Rails.configuration.session_options[:key]
)
end
end
end
The important part is:
Rails.application.config.assets.precompile += %w( alchemy/alchemy.js alchemy/alchemy.css alchemy/print.css )
Be sure to put it inside an
initializer
block. So the main app gets loaded before changing the setting.
As Argument you should pass an array of all the assets you want to be precompiled together with the main app ones.
2 Kommentare
Thanks!
+1, thanks for sharing!
I was suspecting something easy like that could be done in the engine.rb .