如何让 rake 任务在 dev 以外的环境中运行? [英] How can I make rake tasks run in an environment other than dev?
问题描述
我有一台具有特殊登台"环境的登台机器.我总是忘记在该机器上运行 rake 任务,例如:
I have a staging machine with a special "staging" environment. I always forget to run rake tasks on that machine like:
rake jobs:work RAILS_ENV=staging
所以我最终做了:
rake jobs:work
然后我很奇怪为什么我的数据库中没有任何变化.哦!那是因为我不记得提供 RAILS_ENV=staging.
And then I'm mystified why nothing has changed in my database. Doh! It's because I didn't remember to supply RAILS_ENV=staging.
但我永远不需要在该服务器上运行任何开发环境.默认情况下,如何让 rake 任务在暂存"环境中运行?
But I will never, ever need to run anything as the development environment on that server. How can I make rake tasks run in the "staging" environment by default?
推荐答案
您可以将设置环境变量 RAILS_ENV
的行放在一个文件中,该文件将在您登录机器时运行.例如,我是一个 bash 用户,所以我把这行
You can put a line that sets the environment variable RAILS_ENV
in a file that will get run when you log onto the machine. For example, I'm a bash user, so I'd put the line
export RAILS_ENV=staging
在 ~/.bashrc(仅适用于我)或/etc/bashrc(适用于登录到机器的每个人)中.
In either ~/.bashrc (just for me) or /etc/bashrc (for everyone who logs onto the machine).
希望这会有所帮助!
这篇关于如何让 rake 任务在 dev 以外的环境中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!