Search code examples
ruby-on-railsherokustaging

Are there any reasons not to use RAILS_ENV=staging on Heroku?


The Heroku documentation at https://devcenter.heroku.com/articles/deploying-to-a-custom-rails-environment says I shouldn't use a staging.rb file to define my staging environment.

It may be tempting to create another custom environment such as “staging” and create a config/environments/staging.rb and deploy to a Heroku app with RAILS_ENV=staging.

This is not a good practice. Instead we recommend always running in production mode and modifying any behavior by setting your config vars.

I think this is terrible advice and conflicts with well-established Rails best practice. However, I'm not here to argue about best practices. I'm here to ask:

Are there any reasons not to use RAILS_ENV=staging on Heroku?

Is there anything that will break if I create a staging.rb file and set the xxx_ENV config vars like this?

heroku config:add RACK_ENV=staging --remote staging
heroku config:add RAILS_ENV=staging --remote staging

Solution

  • No, there isn't anything that will break if you do this.

    However, I do think that Heroku is right here (note that I work at Heroku). It introduces possible differences between your staging and production environments, when the only thing that changes between them should be configuration variables.
    Heroku already provides a secure mean of setting configuration variables, with the config:set command.
    Using 2 config files means you have to maintain the same configuration twice, and possible can have issues because you updated the configuration correctly in staging, but incorrectly in production.

    As a side note, RACK_ENV should only ever have 3 values: production, development and none. See https://www.hezmatt.org/~mpalmer/blog/2013/10/13/rack_env-its-not-for-you.html