How do I force RAILS_ENV=development from within environment.rb or initializers?

15,152

Solution 1

Why don't you change your production.rb config to match the settings found in development.rb?

Solution 2

Setting it right at the top of environment.rb with:

RAILS_ENV = 'development'

should do it. It's possible that passenger overrides this, though.

If you don't have access to the passenger config but you do have access to your virtual hosts then you can also just force it in there with:

RailsEnv development

Solution 3

In envriornment.rb you could add:

RAILS_ENV="production"
RAILS_ENV.freeze

That way when it tries to get reset later, it will fail.

I'm not sure what other ramifications this will have later or if it will permeate everywhere within rails.

Solution 4

Instead of setting ENV["RAILS_ENV"] in environment.rb, do so in boot.rb. See here for details.

Share:
15,152
btelles
Author by

btelles

Updated on June 11, 2022

Comments

  • btelles
    btelles almost 2 years

    Our host does not allow us to modify the passenger config file (i.e. the apache config OR the vhosts file), but we'd like to run rails in dev mode. So we have to specify the environment (prod/dev/test) in one of the files that rails loads AS the application is restarted. Anyone know how to do this?

    We've tried the following with no luck:

    #environment.rb (before any other code is executed)
      `RAILS_ENV=development`          # using back ticks
      ENV['RAILS_ENV'] = 'development' # assigning to a constant
      RAILS_ENV='development'          # as suggested by one of the answers, unfortunately does not work.