如何使 rails 中的自定义环境成为默认环境? [英] How can I make a custom environment in rails a default environment?
问题描述
i created
通过添加新文件 config/environments/staging.rb
在我的 rails 应用程序中创建了一个自定义暂存环境,与 config/environments/development 相同.rb
然后添加数据库配置 config/database.yml
i created
a custom staging environment in my rails app by adding new file config/environments/staging.rb
, same as config/environments/development.rb
and then added database config config/database.yml
staging:
adapter: sqlite3
database: db/staging.sqlite3
pool: 5
timeout: 5000
现在,我想让staging
成为我的rails应用程序的默认环境
,而不是开发.如何实现?
now, i want to make staging
the default environment
of my rails application instead of development.How to achieve it?
推荐答案
理想情况下,您必须像
export RAILS_ENV=staging
因为 rails
完全依赖于环境变量.但就像你说的
because rails
is fully dependent on environment variable. But like you said
在用户的 ~/.bashrc 或 ~/.bash_profile 文件中添加 RAILS_ENV.会使这个应用程序依赖于控制台,难道它不应该独立于 ~/.bashrc 或 ~/.bash_profile 文件工作吗?
adding RAILS_ENV in ~/.bashrc or ~/.bash_profile file of the user. will make this application depent on the console, shouldn't it just work independent of ~/.bashrc or ~/.bash_profile file?
显然,这是另一种选择.在 config/boot.rb
Obviously, this is another option. Include this line at the top of config/boot.rb
ENV["RACK_ENV"] = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "staging"
这将适用于任何地方.我在以下地方测试过
This will work everywhere. I have tested in following places
- Rails 4
- 耙
- 服务器
- 控制台
- dbconsole
- 如果在
bashrc
或zshrc
等中设置,它会选择环境
- Rails 4
- Rake
- Server
- Console
- dbconsole
- It will pick the environment if it is set in
bashrc
orzshrc
etc.
这篇关于如何使 rails 中的自定义环境成为默认环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!