问题
I'm relatively new to Ruby on Rails and occasionally I find this convention-over-configuration stuff a little confusing as a lot of things seemed to be hidden from the developer, as in this case.
I'm using rails 2.3.8 and when I run my app locally through NetBeans 6.9/Mongrel on my system it runs using the development environment parameters.. when I deploy it to a Fedora box and run it there in Apache HTTPD it automatically runs using the production environment parameters.
How does my app know which environment to use? I haven't changed anything in my app to set the environment.. both versions locally and on my Fedora box are identical. I can't find anywhere in the code where it is setting the environment.. so how is this working?
Thanks.
回答1:
In httpd.conf file, write the following in VirtualHost:-
## Specify Rails Environment here, default value is "production"
RailsEnv development
Thanks...
回答2:
The primary way to specify rails mode is RAILS_ENV
environment variable (I assume development
is default, when nothing is specified). You can check its value in bash, echo $RAILS_ENV
.
You can also modify ENV['RAILS_ENV']
in your config file to change the mode:
ENV['RAILS_ENV'] = 'production'
edit
I've never used rails with apache, but I think passenger mod can also specify this variable somewhere, checking apache configs might help.
来源:https://stackoverflow.com/questions/4450843/ruby-on-rails-how-to-set-which-development-environment-an-app-runs-in