mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Autoloading notes in the upgrading guide
This commit is contained in:
parent
e0d77f124d
commit
43ff2bfef0
1 changed files with 53 additions and 1 deletions
|
@ -78,6 +78,58 @@ To allow you to upgrade to new defaults one by one, the update task has created
|
|||
Upgrading from Rails 6.1 to Rails 7.0
|
||||
-------------------------------------
|
||||
|
||||
### Applications need to run in `zeitwerk` mode
|
||||
|
||||
Applications still running in `classic` mode have to switch to `zeitwerk` mode. Please check the [upgrading guide for Rails 6.0](https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#autoloading) for details.
|
||||
|
||||
### The setter `config.autoloader=` has been deleted
|
||||
|
||||
In Rails 7 there is no configuration point to set the autoloading mode, `config.autoloader=` has been deleted. If you had it set to `:zeitwerk` for whatever reason, just remove it.
|
||||
|
||||
### `ActiveSupport::Dependencies` private API has been deleted
|
||||
|
||||
The private API of `ActiveSupport::Dependencies` has been deleted. That includes methods like `hook!`, `unhook!`, `depend_on`, `require_or_load`, `mechanism`, and many others.
|
||||
|
||||
A few of highlights:
|
||||
|
||||
* If you used `ActiveSupport::Dependencies.constantize` or ``ActiveSupport::Dependencies.safe_constantize`, just change them to `String#constantize` or `String#safe_constantize`.
|
||||
|
||||
```ruby
|
||||
ActiveSupport::Dependencies.constantize("User") # NO LONGER POSSIBLE
|
||||
"User".constantize # 👍
|
||||
```
|
||||
|
||||
* Any usage of `ActiveSupport::Dependencies.mechanism`, reader or writer, has to be replaced by accessing `config.cache_classes` accordingly.
|
||||
|
||||
* If you want to trace the activity of the autoloader, `ActiveSupport::Dependencies.verbose=` is no longer available, just throw `Rails.autoloaders.log!` in `config/application.rb`.
|
||||
|
||||
Auxiliary internal classes or modules are also gone, like like `ActiveSupport::Dependencies::Reference`, `ActiveSupport::Dependencies::Blamable`, and others.
|
||||
|
||||
### Autoloading during initialization
|
||||
|
||||
Applications that autoloaded reloadable constants during initialization outside of `to_prepare` blocks got those constants unloaded and had this warning issued since Rails 6.0:
|
||||
|
||||
```
|
||||
DEPRECATION WARNING: Initialization autoloaded the constant ....
|
||||
|
||||
Being able to do this is deprecated. Autoloading during initialization is going
|
||||
to be an error condition in future versions of Rails.
|
||||
|
||||
...
|
||||
```
|
||||
|
||||
If you still get this warning in the logs, please check the section about autoloading when the application boots in the [autoloading guide](https://guides.rubyonrails.org/v7.0/autoloading_and_reloading_constants.html#autoloading-when-the-application-boots). You'd get a `NameError` in Rails 7 otherwise.
|
||||
|
||||
### Ability to configure `config.autoload_once_paths`
|
||||
|
||||
`config.autoload_once_paths` can be set in the body of the application class defined in `config/application.rb` or in the configuration for environments in `config/environments/*`.
|
||||
|
||||
Similarly, engines can configure that collection in the class body of the engine class or in the configuration for environments.
|
||||
|
||||
After that, the collection is frozen, and you can autoload from those paths. In particular, you can autoload from there during initialization. They are managed by the `Rails.autoloaders.once` autoloader, which does not reload, only autoloads/eager loads.
|
||||
|
||||
If you configured this setting after the environments configuration has been processed and are getting `FrozenError`, please just move the code.
|
||||
|
||||
### `ActionDispatch::Request#content_type` now returned Content-Type header as it is.
|
||||
|
||||
Previously, `ActionDispatch::Request#content_type` returned value does NOT contain charset part.
|
||||
|
@ -173,7 +225,7 @@ FFmpeg v3.4+.
|
|||
|
||||
Image transformation will now use libvips instead of ImageMagick. This will reduce
|
||||
the time taken to generate variants as well as CPU and memory usage, improving response
|
||||
times in apps that rely on active storage to serve their images.
|
||||
times in apps that rely on active storage to serve their images.
|
||||
|
||||
The `:mini_magick` option is not being deprecated, so it is fine to keep using it.
|
||||
|
||||
|
|
Loading…
Reference in a new issue