Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.
like image 403
btelles Avatar asked Dec 16 '09 16:12

btelles


3 Answers

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
like image 110
rfunduk Avatar answered Sep 28 '22 17:09

rfunduk


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

like image 30
jonnii Avatar answered Sep 28 '22 15:09

jonnii


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.

like image 35
Dan McNevin Avatar answered Sep 28 '22 17:09

Dan McNevin