Having a very confusing issue
My local app is running in its staging
environment. I use puma-dev for the server and when I tail it by running tail -f ~/Library/Logs/puma-dev.log
it says that the environment is development, but when I log out to my view using <%= Rails.env %>
it says staging
and the app tries to use any staging
environment variables that it needs instead of the variables for the development
environment.
The app has environments for Development
, Staging
, Test
and Production
. It is only recently that I noticed this was running in staging, I'm not exactly sure how or when it switched over but for the last couple years it was running in dev just fine, I recently added a staging env to help with a rails upgrade and some point over the last week this started running in staging.
I always thought this was set by the server when started but with puma-dev saying its env is development. I am at a loss for how this is trying to run in staging.
puma-dev output when starting:
io[19626]: Puma starting in single mode...
io[19626]: * Version 4.3.5 (ruby 2.4.6-p354), codename: Mysterious Traveller
io[19626]: * Min threads: 0, max threads: 5
io[19626]: * Environment: development
Can anyone shed some light on exactly where or how a Rails app decides to set its Environment because for the life of me, I cannot find it in the app.
As a test based on the answer below (which was useful) I log out these 3 variables:
<%= Rails.env %>
which ends up beingstaging
<%= ENV["RAILS_ENV"] %>
which ends up showing nothing<%= ENV["RACK_ENV"] %>
which ends up beingdevelopment
Also, if I run the rails console and type in Rails.env
is also returns 'development'.
I also used the suggestion in the answer below and ran RAILS_ENV=development rails server
. When doing that, both ENV["RAILS_ENV"]
and ENV["RACK_ENV"]
were set to development but the application was still running in staging (so the first variable above didn't change but the second one did).
The app is still trying to use all the staging ENV variables that are set (S3, etc.). For this app I also recently updated from Rails 3.* to 4.2 (I know these versions are old. I inherited the apps and am working on it). Which was the reason for adding the staging Environment. I was unable to find anything in the upgrade guides that talks about this kind of issue so I, at first, didn't suspect it was related but I wanted to give as much info as I could on this issue.