The Run-time configuration of rails is controlled by the files in the Config directory.
1. Runtime Environment (Runtime environment)
When developers write code, the requirements are many and varied. In development you may need a lot of logins to load the changed code. When testing, you need to separate the systems from each other. Before publishing, you may need to optimize performance and keep users away from bugs.
To support all this, rials has the concept of runtime configuration. Each environment has its own set of configurations that can run the same application in different environments.
Switching to a running environment allows us to switch from development to testing and to publishing without modifying the code. How do I specify a running environment? It depends on how you run your program, if you use the Script/server and use the-e parameter:
Depot > Ruby script/server–e Development |test| Production
If you use Apche or LIGHTTPD, you should set the RAILS_ENV environment variable, which we'll introduce later.
If you have special needs, you can create your own environment (environment), you need to add your own configuration section to the database configuration, and add a profile to the Config/environment folder.
2. Configure Database Links
File config/database.yml is used to configure the database link, and you will find that it includes three configuration sections, each of which starts with the environment name followed by a colon. The following line must be indented, with the key and corresponding value in the content, separated by a colon. At a minimum, each configuration section must specify a database adapter (DB adapter) and the database used, such as mysql,postgres, and so on. The database adapter has its own specific configuration, and the complete list will be listed later. The following is the database.yml file for our current depot program:
Development:
adapter:mysql
database:depot_development
Username: password
:
host:localhost
# warning:the database defined as ' test ' would be erased and
# re-generated from your development database when Y ou run ' rake '. # don't set this db to the same as development or production.test:
adapter:mysql
Database:depot _test
Username:
Password:
host:localhost
production:
adapter:mysql
Database: Depot_production
username:root
password:prod
host:wibble