Ruby on Rails: How to set which development enviro

2019-09-05 13:14发布

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.

2条回答
劳资没心,怎么记你
2楼-- · 2019-09-05 13:20

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.

查看更多
\"骚年 ilove
3楼-- · 2019-09-05 13:37

In httpd.conf file, write the following in VirtualHost:-

## Specify Rails Environment here, default value is "production"
RailsEnv development

Thanks...

查看更多
登录 后发表回答