Environment: dev vs test
This course explains what Rails means by environment: one of three named modes (development, test and production) tracked by Rails.env and set through the RAILS_ENV variable. It keeps that idea apart from a computer's own setup of editor, Ruby version and PostgreSQL. The lessons read development.rb, test.rb and production.rb line by line, covering code reloading, eager loading, error pages, HTTPS and allowed hosts. They also show how database.yml sends each environment to its own databases, and how -e test and --sandbox combine in the console.
What you'll learn
- ✓How Rails.env and the RAILS_ENV variable pick one of three modes
- ✓Line-by-line differences between development.rb and test.rb
- ✓What production.rb changes: eager loading, error pages, HTTPS and allowed hosts
- ✓How database.yml gives each environment its own databases and connections
- ✓Switching environments with RAILS_ENV or bin/rails console -e test
- ✓How -e and --sandbox answer different questions in a console session
Two kinds of environment
The Rails CLI: rails new course's config lesson named three files in passing: "config/environments/development.rb, test.rb and production.rb each override application.rb for one environment." Then it added: "Environment: dev vs test covers this split later." This is that course.
Read the full lesson free →Curriculum
7 lessonsTwo kinds of environment
Separates a computer's development setup from Rails' environment, one of three modes tracked by Rails.env.
Rails.env: three named modes, one variable
Shows Rails.env as an EnvironmentInquirer, how RAILS_ENV sets it, and the three modes with their config files.
development.rb vs test.rb, line by line
Compares development.rb and test.rb on reloading, eager loading, and where jobs, uploads and emails go.
production.rb: what changes for real users
Covers production.rb settings: eager loading at boot, hidden error details, forced HTTPS and allowed hostnames.
database.yml: separate databases per environment
Reads database.yml, where shared defaults and four connections per environment point each mode at separate databases.
Switching environments
Switches environments with RAILS_ENV or console -e test, and explains how -e differs from --sandbox.
Putting it together: one Rails.env, every file
Traces one Rails.env value through every config file and database block covered in the course.