Where is the RAILS_ENV?
ruby-on-rails
Solution
`RAILS_ENV` is just an environmental variable which is set in the shell or the operating system itself (or when invoking the process).
Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs. For example, a running process can query the value of the `TEMP` environment variable to discover a suitable location to store temporary files, or the `HOME` or `USERPROFILE` variable to find the directory structure owned by the user running the process. https://en.wikipedia.org/wiki/Environment_variable
`ENV["RAILS_ENV"]` simply contains a string such as "production", "development" or "test". This tells Rails which configuration file in `/config/environments` to load - and which hash key in `database.yml` to use for the database.
For example if `ENV["RAILS_ENV"] == "foo"` Rails will:
- load `/config/environments/foo.rb`
- look for the key `foo` in database.yml.
- `Rails.env.foo?` will be true.
The Rails concept of environment is thus somewhat different than the general computing concept - a Rails environment is a broader term for a set of settings and a database that serve different purposes such as automated testing or production.
See also:
- Store config in the environment
Problem
I'm looking at this article about rake commands but don't where the RAILS_ENV is. Is that in a specific file somewhere? ``` db:create Creates the database for the current RAILS_ENV environment. If RAILS_ENV is not specified it defaults to the development and test databases. ```