I have an app that I recently updated to Rails 3.2.1 (from Rails 3.0.x) and have refactored the JS and CSS assets to make use of the new asset pipeline. Th
Here's what I came up with. In the assets that need app configuration, I place this line at the very beginning:
<% require "#{Rails.root}/config/initializers/load_config.rb" unless defined?(AppConfig) %>
... and add .erb
to the file name, so that video_player.js.coffee
becomes video_player.js.coffee.erb
. Then I can safely use AppConfig['somekey']
afterwards.
During the asset pre-compilation, it loads app config despite the initialize_on_precompile
set to false
, and does it only once (which avoids constant redefinition issues).
Yes, it's a kludge, but many times nicer than embedding configs in asset files.