aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/autoloading_and_reloading_constants.md
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2018-09-07 23:11:23 +0200
committerXavier Noria <fxn@hashref.com>2018-09-07 23:32:54 +0200
commitc03bba4f1f03bad7dc034af555b7f2b329cf76f5 (patch)
treeb069cc53c5ee48238dd8340129911b1ceafda217 /guides/source/autoloading_and_reloading_constants.md
parentc3e569550ca0a90561fe990f519719ba52402504 (diff)
downloadrails-c03bba4f1f03bad7dc034af555b7f2b329cf76f5.tar.gz
rails-c03bba4f1f03bad7dc034af555b7f2b329cf76f5.tar.bz2
rails-c03bba4f1f03bad7dc034af555b7f2b329cf76f5.zip
trace autoloads, and document hints for troubleshooting
Closes #32885.
Diffstat (limited to 'guides/source/autoloading_and_reloading_constants.md')
-rw-r--r--guides/source/autoloading_and_reloading_constants.md31
1 files changed, 31 insertions, 0 deletions
diff --git a/guides/source/autoloading_and_reloading_constants.md b/guides/source/autoloading_and_reloading_constants.md
index 6298651e4a..b3f923a017 100644
--- a/guides/source/autoloading_and_reloading_constants.md
+++ b/guides/source/autoloading_and_reloading_constants.md
@@ -1350,3 +1350,34 @@ With the [Spring](https://github.com/rails/spring) pre-loader (included with new
Occasionally you may need to explicitly eager_load by using `Rails
.application.eager_load!` in the setup of your tests -- this might occur if your [tests involve multithreading](https://stackoverflow.com/questions/25796409/in-rails-how-can-i-eager-load-all-code-before-a-specific-rspec-test).
+
+## Troubleshooting
+
+### Tracing Autoloads
+
+Active Support is able to report constants as they are autoloaded. To enable these traces in a Rails application, put the following two lines in some initializer:
+
+```ruby
+ActiveSupport::Dependencies.logger = Rails.logger
+ActiveSupport::Dependencies.verbose = true
+```
+
+### Where is a Given Autoload Triggered?
+
+If constant `Foo` is being autoloaded, and you'd like to know where is that autoload coming from, just throw
+
+```ruby
+puts caller
+```
+
+at the top of `foo.rb` and inspect the printed stack trace.
+
+### Which Constants Have Been Autoloaded?
+
+At any given time,
+
+```ruby
+ActiveSupport::Dependencies.autoloaded_constants
+```
+
+has the collection of constants that have been autoloaded so far.