5

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.

5 Answers 5

6

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
1
  • Valiant attempt, but no dice, unfortunately. And I fixed the question so that it's clear that we also do not have access to the vhosts file.
    – btelles
    Commented Dec 16, 2009 at 16:33
5

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

2
  • This should do it. There's nothing magical about "production" as a name. Swapping all the setting (don't forget the config/environments/production.rb file) should do it.
    – edebill
    Commented Dec 16, 2009 at 16:49
  • Eggsellente...I didn't do that initially because...um...I suffer from ...tunnel vision?
    – btelles
    Commented Dec 16, 2009 at 18:00
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.

2

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

-3

RAILS_ENV="production" RAILS_ENV.freeze/ENV 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.

1
  • 1
    Copied from a helpful answer above Commented Jan 22, 2021 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.