Skip to content

Commit 3531ca6

Browse files
committed
Iterate instructions for custom namespaces in Rails < 7.1
1 parent 1df6ad0 commit 3531ca6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

guides/source/autoloading_and_reloading_constants.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,12 +514,13 @@ module Services; end
514514
Rails.autoloaders.main.push_dir("#{Rails.root}/app/services", namespace: Services)
515515
```
516516

517-
Applications running on Rails < 7.1 have to additionally delete the directory from `ActiveSupport::Dependencies.autoload_paths`. Just add this line to the same file:
517+
Rails < 7.1 did not support this feature, but you can still add this additional code in the same file and get it working:
518518

519519
```ruby
520-
# For applications running on Rails < 7.1.
521-
# The argument has to be a string.
522-
ActiveSupport::Dependencies.autoload_paths("#{Rails.root}/app/services")
520+
# Additional code for applications running on Rails < 7.1.
521+
app_services_dir = "#{Rails.root}/app/services" # has to be a string
522+
ActiveSupport::Dependencies.autoload_paths.delete(app_services_dir)
523+
Rails.application.config.watchable_dirs[app_services_dir] = [:rb]
523524
```
524525

525526
Custom namespaces are also supported for the `once` autoloader. However, since that one is set up earlier in the boot process, the configuration cannot be done in an application initializer. Instead, please put it in `config/application.rb`, for example.

0 commit comments

Comments
 (0)