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测试数据库混在一起。
3 个解决方案
#1
78
Assuming you want create the hudson
environment.
假设你想要创建hudson环境。
- Create a new environment file in
config/environments/hudson.rb
. You can start by cloning an existing one, for instanceconfig/environments/test.rb
. - 在config/environments/hudson.rb中创建一个新的环境文件。您可以从克隆现有的配置/环境/test.rb开始。
- Add a new configuration block in
config/database.yml
for your environment. - 在配置/数据库中添加一个新的配置块。yml为您的环境。
- Update any other configuration file you might have under the
config
folder with your new environment, some gems create their ownymls
under theconfig
folder. - 在新环境下更新配置文件夹下的任何其他配置文件,一些gems在config文件夹下创建它们自己的ymls。
- That's all.
- 这是所有。
Now you can start the server
现在可以启动服务器了
rails server -e hudson
or run the console
或运行控制台
rails console hudson
And so on.
等等。
If you are using an older version of Rails, the commands are
如果您正在使用旧版本的Rails,命令是
ruby script/server -e hudson
ruby script/console hudson
#2
9
Updated Answer for Rails 5
Rails 5的更新答案
Create new environment file:
创建新环境文件:
config/environments/staging.rb
Modify the following files to add the environment key 'staging'
修改以下文件以添加环境密钥“staging”
config/cable.yml
config/database.yml
config/secrets.yml
Gemfile (incase you have stage dependent gems)
The new environments can now be used as usual for eg:
新环境现在可以像往常一样使用,例如:
rails server -e staging rails console staging
rails服务器-e暂存rails控制台暂存
Or to do conditional checks:
或者进行条件检查:
rails console staging, Rails.env.staging?
Good place to start for creating new environment and to modify these files is to copy production settings.
创建新环境和修改这些文件的良好起点是复制生产设置。
#3
1
Create a file config/environments/build.rb
which will contain the options specific to your environment.
Add your new environment's database credentials in config/database.yml
.
创建一个文件配置/环境/构建。rb将包含特定于您的环境的选项。在config/database.yml中添加新环境的数据库凭据。
Rock and roll!
摇滚乐!
#1
78
Assuming you want create the hudson
environment.
假设你想要创建hudson环境。
- Create a new environment file in
config/environments/hudson.rb
. You can start by cloning an existing one, for instanceconfig/environments/test.rb
. - 在config/environments/hudson.rb中创建一个新的环境文件。您可以从克隆现有的配置/环境/test.rb开始。
- Add a new configuration block in
config/database.yml
for your environment. - 在配置/数据库中添加一个新的配置块。yml为您的环境。
- Update any other configuration file you might have under the
config
folder with your new environment, some gems create their ownymls
under theconfig
folder. - 在新环境下更新配置文件夹下的任何其他配置文件,一些gems在config文件夹下创建它们自己的ymls。
- That's all.
- 这是所有。
Now you can start the server
现在可以启动服务器了
rails server -e hudson
or run the console
或运行控制台
rails console hudson
And so on.
等等。
If you are using an older version of Rails, the commands are
如果您正在使用旧版本的Rails,命令是
ruby script/server -e hudson
ruby script/console hudson
#2
9
Updated Answer for Rails 5
Rails 5的更新答案
Create new environment file:
创建新环境文件:
config/environments/staging.rb
Modify the following files to add the environment key 'staging'
修改以下文件以添加环境密钥“staging”
config/cable.yml
config/database.yml
config/secrets.yml
Gemfile (incase you have stage dependent gems)
The new environments can now be used as usual for eg:
新环境现在可以像往常一样使用,例如:
rails server -e staging rails console staging
rails服务器-e暂存rails控制台暂存
Or to do conditional checks:
或者进行条件检查:
rails console staging, Rails.env.staging?
Good place to start for creating new environment and to modify these files is to copy production settings.
创建新环境和修改这些文件的良好起点是复制生产设置。
#3
1
Create a file config/environments/build.rb
which will contain the options specific to your environment.
Add your new environment's database credentials in config/database.yml
.
创建一个文件配置/环境/构建。rb将包含特定于您的环境的选项。在config/database.yml中添加新环境的数据库凭据。
Rock and roll!
摇滚乐!