5414: Control initializer load order using require_relative instead of alphabetical...
authorTom Clegg <tom@curoverse.com>
Mon, 13 Apr 2015 17:47:03 +0000 (13:47 -0400)
committerTom Clegg <tom@curoverse.com>
Mon, 13 Apr 2015 17:47:03 +0000 (13:47 -0400)
services/api/config/initializers/zz_load_config.rb
services/api/config/initializers/zz_preload_all_models.rb

index 8b454b6a72708f5821a0bdcb300fdd49446eb8c0..3b516dacadff0a4b4031a84be772c171df7f1197 100644 (file)
@@ -1,3 +1,11 @@
+begin
+  # If secret_token.rb exists here, we need to load it first.
+  require_relative 'secret_token.rb'
+rescue LoadError
+  # Normally secret_token.rb is missing and the secret token is
+  # configured by application.yml (i.e., here!) instead.
+end
+
 $application_config = {}
 
 %w(application.default application).each do |cfgfile|
index 1a76b72ed320f8ee9e2f261f1b2efb9b74eb9920..d5af524903c8890f3bbe8a2327b955e04900aba2 100644 (file)
@@ -1,5 +1,10 @@
 # See http://aaronvb.com/articles/37-rails-caching-and-undefined-class-module
 
+# Config must be done before we load model class files; otherwise they
+# won't be able to use Rails.configuration.* to initialize their
+# classes.
+require_relative 'zz_load_config.rb'
+
 if Rails.env == 'development'
   Dir.foreach("#{Rails.root}/app/models") do |model_file|
     require_dependency model_file if model_file.match /\.rb$/