Skip to content

Commit 1b5134c

Browse files
committed
update reload documentation
refs #358
1 parent 2cbeeac commit 1b5134c

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

README.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4079,6 +4079,30 @@ Use [grape-reload](https://github.com/AlexYankee/grape-reload).
40794079

40804080
### Reloading in Rails Applications
40814081

4082+
#### Rails 7+ (Zeitwerk)
4083+
4084+
Rails 7+ uses [Zeitwerk](https://github.com/fxn/zeitwerk) as the default autoloader, which automatically handles reloading of code in development mode without any additional configuration.
4085+
4086+
If your API files are in `app/api`, Zeitwerk will automatically autoload and reload them. No additional configuration is needed.
4087+
4088+
If you encounter issues with reloading, ensure that:
4089+
4090+
1. Your API files follow Zeitwerk naming conventions (file names should match class names)
4091+
2. The `config.enable_reloading` is set to `true` in `config/environments/development.rb` (this is the default)
4092+
4093+
For troubleshooting autoloading issues, you can add logging:
4094+
4095+
```ruby
4096+
# config/application.rb (after loading the framework defaults)
4097+
Rails.autoloaders.log!
4098+
```
4099+
4100+
See the [Rails Autoloading and Reloading Constants guide](https://guides.rubyonrails.org/autoloading_and_reloading_constants.html) for more information.
4101+
4102+
#### Rails 6 and Earlier
4103+
4104+
For Rails versions before 7, you need to configure reloading manually.
4105+
40824106
Add API paths to `config/application.rb`.
40834107

40844108
```ruby
@@ -4097,28 +4121,12 @@ if Rails.env.development?
40974121
api_reloader = ActiveSupport::FileUpdateChecker.new(api_files) do
40984122
Rails.application.reload_routes!
40994123
end
4100-
ActionDispatch::Callbacks.to_prepare do
4124+
ActiveSupport::Reloader.to_prepare do
41014125
api_reloader.execute_if_updated
41024126
end
41034127
end
41044128
```
41054129

4106-
For Rails >= 5.1.4, change this:
4107-
4108-
```ruby
4109-
ActionDispatch::Callbacks.to_prepare do
4110-
api_reloader.execute_if_updated
4111-
end
4112-
```
4113-
4114-
to this:
4115-
4116-
```ruby
4117-
ActiveSupport::Reloader.to_prepare do
4118-
api_reloader.execute_if_updated
4119-
end
4120-
```
4121-
41224130
See [StackOverflow #3282655](http://stackoverflow.com/questions/3282655/ruby-on-rails-3-reload-lib-directory-for-each-request/4368838#4368838) for more information.
41234131

41244132
## Performance Monitoring

0 commit comments

Comments
 (0)