From 880ae9406484deb4f7b1abe11a5c1ec25d4485c6 Mon Sep 17 00:00:00 2001 From: Michael Baudino Date: Tue, 9 Oct 2018 09:12:32 +0200 Subject: [PATCH] Reword Rails best practices --- docs/rails.md | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/rails.md b/docs/rails.md index c494225..b54f40f 100644 --- a/docs/rails.md +++ b/docs/rails.md @@ -1,19 +1,25 @@ -# Rails conventions +# Rails-specific best practices -## App behavior should be configured via environment variables +## Application configuration -When implementing new features, it should not depend on current -`RAILS_ENV` value, but environment variable(s) specific to the -feature. +Application configuration should **depend on environment variables**, +and absolutely **not rely on `RAILS_ENV`** value (nor `Rails.env`), +respecting the [12-factor app methodology][12-factor config]. -* Avoid modifying `config/environments/*.rb`, and keep default - Rails configuration (this will also help when updating Rails) -* Avoid testing: +Specifically, the following rules should be followed: + +* Avoid modifying `config/environments/*.rb`: keep default Rails configuration + in there untouched (this will also make Rails upgrades a lot smoother) +* Write application configuration in `config/application.rb` +* Avoid testing any of: + * `ENV["RACK_ENV"]` + * `ENV["RAILS_ENV"]` * `Rails.env.development?` * `Rails.env.production?` * `Rails.env.test?` Examples: + ``` ruby # bad: module MyRailsApp @@ -75,3 +81,5 @@ Rails.application.routes.draw do end end ``` + +[12-factor config]: https://12factor.net/config