How does rails differentiate between development vs production machine (or does it not) - like when we push to heroku / ec2 / server in grandma’s basement / what have you - How does the app /framework know that “oh, this is the production machine” - and so must look at the production group for the gem file, and for the database.yml, oh and I must also skip the tests, etc. etc.
The app server starting up will pass along the environment it should be running as. By default it assumes “development” unless you tell it otherwise, right?
So - places like heroku will tell it otherwise. Sometimes it’s passed as a flag to the server – for example, with webrick:
rails s -e production. Other times it’s an environmental variable:
export RAILS_ENV='production' && rails s.
If only Rails were open-source, we’d be able to examine its code to see how it works!
So, based on my reading of the
env method, Rails looks for an environment variable of RAILS_ENV, then RACK_ENV, then defaults to “development”.