Rails runs an app in one named environment at a time, chosen by the RAILS_ENV variable, and loads that environment's settings on boot. Three come by default:
development reloads code after every change, shows detailed error pages and includes debugging tools like the web console.
test runs the test suite against its own database, loads fixtures and rolls back each test's changes.
production is tuned for performance. It loads all code once at boot, turns on caching and hides error details from users, so teams add error monitoring there.
# Check current environment
Rails.env.development? # true/false
Rails.env # "development"
# Environment-specific code
if Rails.env.production?
# Production-only code
end
Each environment has its own file in config/environments/ and its own section in config/database.yml. To add a custom environment such as staging, you create both yourself.
# Custom environments
RAILS_ENV=staging rails server
Rewriting in plainer words…
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.