💎 Ruby on Rails
Beginner
What are Rails environments and how do you check the current one?
Answer
Rails runs in one of its configured environments (development, test, production, or custom ones). Check the current environment with Rails.env, which returns a string. Use predicates: Rails.env.development?, Rails.env.test?, Rails.env.production?. Set the environment via the RAILS_ENV environment variable: RAILS_ENV=production rails server. Environment-specific configuration in config/environments/ controls things like email delivery, caching, asset compilation, and logging verbosity.