The code loader is disabled by default during production. Therefore, if you call require_dependency at the top of the file, it will be executed only once.
The Rails 3 change you were talking about is very small. You can usually call Foo
and it will be loaded from app/models/foo.rb
automatically. Before it can also be loaded from lib/foo.rb
(These app/models
and lib
directories are called startup paths.) The Rails team decided to remove lib from startup paths in the third version. You can still get it back. But it is recommended that you leave less frequently modified and project-specific files in lib. If you have something that does not apply to any of the subdirectories of the default applications, such as app / models or app / controller, you do not need to embed them in lib. You can add your own subdirectory. For example, I have app/presenters
. There is a discussion on the old issue if you would like more information about this.
source share