如何在 Ruby on Rails 中创建新环境?

问题描述:

我正在尝试创建一个新环境(构建),以便与 hudson 一起使用.

I'm trying to create a new environment (build) for using it with hudson.

我这样做是因为我不想将我的测试数据库与 hudson 测试数据库混淆.

I'm doing this because I didn't want to mix up my test databases with hudson test database.

假设您要创建 hudson 环境.

Assuming you want create the hudson environment.

  1. config/environments/hudson.rb 中创建一个新的环境文件.您可以先克隆一个现有的,例如 config/environments/test.rb.
  2. config/database.yml 中为您的环境添加一个新的配置块.
  3. 使用新环境更新 config 文件夹下的任何其他配置文件,一些 gem 在 config 下创建自己的 ymls文件夹.
  4. 仅此而已.
  1. Create a new environment file in config/environments/hudson.rb. You can start by cloning an existing one, for instance config/environments/test.rb.
  2. Add a new configuration block in config/database.yml for your environment.
  3. Update any other configuration file you might have under the config folder with your new environment, some gems create their own ymls under the config folder.
  4. That's all.

现在可以启动服务器了

rails server -e hudson

或者运行控制台

rails console hudson

等等.

如果您使用的是旧版 Rails,则命令为

If you are using an older version of Rails, the commands are

ruby script/server -e hudson
ruby script/console hudson