The runtime configuration of your application is performed by two files.
One, config/environment.rb, is environment independent—it is used regardless
of the setting of RAILS_ENV.
The second file does depend on the environment:
Rails looks for a file named for the current environment in the
directory config/environments and loads it during the processing of environment.
rb.
The standard three environments (development.rb, production.rb,
and test.rb) are included by default. You can add your own file if you’ve
defined new environment types.
Environment files typically do three things.
• They set up the Ruby load path. This is how your application can
find things such as models and views when it’s running.
• They create resources used by your application (such as the logger).
• They set various configuration options, both for Rails and for your
application.
The first two of these are normally application-wide and so are done in
environment.rb. The configuration options often vary depending on the environment
and so are likely to be set in the environment-specific files in the
environments directory.
The Load Path
The standard environment automatically includes the following directories
(relative to your application’s base directory) into your application’s load
path.
1. test/mocks/environment. As these are first in the load path, classes
defined here override the real versions, enabling you to replace live
functionality with stub code during testing. This is described starting
on page 161.
2. All directories whose names start with an underscore or a lowercase
letter under app/models and components.子目录
3.The directories app, app/models, app/controllers, app/helpers, app/apis,
components, config, lib, vendor, and vendor/rails/*.
Each of these directories is added to the load path only if it exists.
Application-wide Resources
environment.rb creates an instance of a Logger that will log messages to
log/environment.log. It sets this to be the logger used by Active Record,
Action Controller, and Action Mailer (unless your environment-specific
configuration files had already set their own logger into any of these components).
environment.rb also tells Action Controller and Mailer to use app/views as
the starting point when looking for templates. Again, this can be overridden
in the environment-specific configurations.
Configuration Parameters
You configure Rails by setting various options in the Rails modules. Typically
you’ll make these settings either at the end of environment.rb (if you
want the setting to apply in all environments) or in one of the environmentspecific
files in the environments directory.
We provide a listing of all these configuration parameters in Appendix B