Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
- [Reloading API Changes in Development](#reloading-api-changes-in-development)
- [Reloading in Rack Applications](#reloading-in-rack-applications)
- [Reloading in Rails Applications](#reloading-in-rails-applications)
- [Rails 7+ (Zeitwerk)](#rails-7-zeitwerk)
- [Performance Monitoring](#performance-monitoring)
- [Active Support Instrumentation](#active-support-instrumentation)
- [Hook Points](#hook-points)
Expand Down Expand Up @@ -4079,6 +4080,25 @@ Use [grape-reload](https://github.com/AlexYankee/grape-reload).

### Reloading in Rails Applications

#### Rails 7+ (Zeitwerk)

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.

If your API files are in `app/api`, Zeitwerk will automatically autoload and reload them. No additional configuration is needed.

If you encounter issues with reloading, ensure that:

1. Your API files follow Zeitwerk naming conventions (file names should match class names).
2. The `config.enable_reloading` is set to `true` in `config/environments/development.rb` (this is the default).

For troubleshooting autoloading issues, have a look at the [Rails documentation](https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#troubleshooting).

See the [Rails Autoloading and Reloading Constants guide](https://guides.rubyonrails.org/autoloading_and_reloading_constants.html) for more information.

#### Rails 6 and Earlier

For Rails versions before 7, you need to configure reloading manually.

Add API paths to `config/application.rb`.

```ruby
Expand All @@ -4097,28 +4117,12 @@ if Rails.env.development?
api_reloader = ActiveSupport::FileUpdateChecker.new(api_files) do
Rails.application.reload_routes!
end
ActionDispatch::Callbacks.to_prepare do
ActiveSupport::Reloader.to_prepare do
api_reloader.execute_if_updated
end
end
```

For Rails >= 5.1.4, change this:

```ruby
ActionDispatch::Callbacks.to_prepare do
api_reloader.execute_if_updated
end
```

to this:

```ruby
ActiveSupport::Reloader.to_prepare do
api_reloader.execute_if_updated
end
```

See [StackOverflow #3282655](http://stackoverflow.com/questions/3282655/ruby-on-rails-3-reload-lib-directory-for-each-request/4368838#4368838) for more information.

## Performance Monitoring
Expand Down