Ruby-on-rails 如何将 RAILS_ENV 设置为所有后续 rake 命令的生产?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3113828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:49:21  来源:igfitidea点击:

How can I set RAILS_ENV to production for all subsequent rake commands?

ruby-on-railsrake

提问by nasmorn

As a bonus how do I set this in a config, so that when I log into my production server I don't have to retype it.

作为奖励,我如何在配置中设置它,以便当我登录到我的生产服务器时,我不必重新输入它。

回答by Nicolas Viennot

in your .bashrc, put:

在您的 .bashrc 中,输入:

if [[ $- != *i* ]] ; then
    # Shell is non-interactive.  Be done now!
    return
fi

export RAILS_ENV=production

Be careful, you will always be in production mode when you login !

请注意,登录时您将始终处于生产模式!

回答by John Bachir

I tend to want to set it conscientiously with each command also.

我也倾向于用每个命令认真地设置它。

Although I don't do much directly on the server, I'm usually using capistrano. So if I was working directly on the server a lot, I might want to set it permanently. Which, BTW, Larry didn't mention how to do:

虽然我没有直接在服务器上做很多事情,但我通常使用 capistrano。所以如果我经常直接在服务器上工作,我可能想永久设置它。顺便说一句,拉里没有提到如何做:

$ RAILS_ENV=production
$ rake foo
$ rake bar

回答by Larry K

I use

我用

rake task_name RAILS_ENV=production

耙子任务名称 RAILS_ENV=生产

That way I have to type the phrase "production" conscientiously. Fewer booboos!

这样我就必须认真地输入“生产”这个短语。更少的嘘声!

Bonus answer:

奖金答案:

Set the environment variable RAILS_ENV to production.

将环境变量 RAILS_ENV 设置为生产。

You can do that as a shell alias. Eg "set_production" Exact syntax depends on your shell type.

您可以将其作为 shell 别名。例如“set_production” 确切的语法取决于您的 shell 类型。

Or you can set the env variable when you login on the production system.

或者您可以在登录生产系统时设置 env 变量。