Background
I have an application that I recently upgraded to Rails 3.2.1 (from Rails 3.0.x) and redesigned JS and CSS assets to use the new asset pipeline. The app is hosted on Heroku using the Celadon Cedar Rack.
Application configuration
I save the specific application configuration in a YAML file called app_config.yml and load it into the global variable APP_CONFIG using the initializer:
# config/initializers/load_app_config.rb app_config_contents = YAML.load_file("#{Rails.root.to_s}/config/app_config.yml") app_config_contents["default"] ||= {} APP_CONFIG = app_config_contents["default"].merge( app_config_contents[Rails.env] || {} ).symbolize_keys
Heroku asset compilation
Heroku supports the Rails resource pipeline built into the cedar stack. When you click an application in Heroku, it automatically calls rake assets:precompile on the server as a step in the deployment process. However, it does this in an isolated environment without access to the database or normal ENV-vars.
If the application is allowed to properly initialize during pre-compilation of the asset, an error occurs when connecting to the database. This is easily solved by adding the following to the application.rb file:
# Do not load entire app when precompiling assets config.assets.initialize_on_precompile = false
My problem
When initialize_on_precompile = false set, none of the initializers in config/initializers/* starts. The problem I am facing is that I need the APP_CONFIG variable to be available during resource precompilation.
How can I get load_app_config.rb to load during asset compilation without initializing the entire application? Can I do something with the group parameter passed to Rails :: Application.initialize!
jshkol Feb 10 2018-12-12T00: 00Z
source share