Ruby on Rails: How to set which development environment an app runs in?

落花浮王杯 提交于 2019-12-12 04:15:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!