mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add a section about autoloading in the Getting Started Guide
This commit is contained in:
parent
933284aaba
commit
31ad3f1529
1 changed files with 18 additions and 0 deletions
|
@ -361,6 +361,24 @@ confirming that the `root` route is also mapped to the `index` action of
|
|||
TIP: To learn more about routing, see [Rails Routing from the Outside In](
|
||||
routing.html).
|
||||
|
||||
Autoloading
|
||||
-----------
|
||||
|
||||
Rails applications **do not** use `require` to load application code.
|
||||
|
||||
You may have noticed that `ArticlesController` inherits from `ApplicationController`, but `app/controllers/articles_controller.rb` does not have anything like
|
||||
|
||||
```ruby
|
||||
require "application_controller" # DON'T DO THIS.
|
||||
```
|
||||
|
||||
Application classes and modules are available everywhere, you do not need and **should not** load anything under `app` with `require`. This feature is called _autoloading_, and you can learn more about it in [_Autoloading and Reloading Constants_](https://guides.rubyonrails.org/autoloading_and_reloading_constants.html).
|
||||
|
||||
You only need `require` calls for two use cases:
|
||||
|
||||
* To load files under the `lib` directory.
|
||||
* To load gem dependencies that have `require: false` in the `Gemfile`.
|
||||
|
||||
MVC and You
|
||||
-----------
|
||||
|
||||
|
|
Loading…
Reference in a new issue