You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/source/autoloading_and_reloading_constants.md
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1350,3 +1350,34 @@ With the [Spring](https://github.com/rails/spring) pre-loader (included with new
1350
1350
1351
1351
Occasionally you may need to explicitly eager_load by using `Rails
1352
1352
.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).
1353
+
1354
+
##Troubleshooting
1355
+
1356
+
###Tracing Autoloads
1357
+
1358
+
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:
1359
+
1360
+
```ruby
1361
+
ActiveSupport::Dependencies.logger=Rails.logger
1362
+
ActiveSupport::Dependencies.verbose=true
1363
+
```
1364
+
1365
+
###Where is a Given Autoload Triggered?
1366
+
1367
+
If constant`Foo` is being autoloaded, and you'd like to know where is that autoload coming from, just throw
1368
+
1369
+
```ruby
1370
+
putscaller
1371
+
```
1372
+
1373
+
at the top of`foo.rb` and inspect the printed stack trace.
1374
+
1375
+
###Which Constants Have Been Autoloaded?
1376
+
1377
+
At any given time,
1378
+
1379
+
```ruby
1380
+
ActiveSupport::Dependencies.autoloaded_constants
1381
+
```
1382
+
1383
+
has the collection of constants that have been autoloaded so far.