Ruby on rails Opsworks Rails控制台环境

Ruby on rails Opsworks Rails控制台环境,ruby-on-rails,aws-opsworks,Ruby On Rails,Aws Opsworks,我尝试在amazon opsworks中运行rails控制台,我尝试过: sudo rails console -e production sudo rails console production RAILS_ENV=production sudo rails console RAILS_ENV=production RACK_ENV=production sudo rails console 使用这些命令中的每一个,控制台都会在开发环境中旋转起来。要在我选择的环境中启动此控制台,我需要做什

我尝试在amazon opsworks中运行rails控制台,我尝试过:

sudo rails console -e production
sudo rails console production
RAILS_ENV=production sudo rails console
RAILS_ENV=production RACK_ENV=production sudo rails console

使用这些命令中的每一个,控制台都会在开发环境中旋转起来。要在我选择的环境中启动此控制台,我需要做什么?

假设您已通过ssh连接到实例中

sudo su deploy  # switch to the app user
cd /srv/www/myapp/current  # your deploy dir might be different (check logs if unsure)
RAILS_ENV=production bundle exec rails console
$cd/srv/www/yourapplication/current

$sudo bundle exec rails控制台
解决方案1(更快): 可以使用此gem从.env(.environment)-文件添加环境变量。您必须在这个文件中写下需要加载的所有键和值

解决方案2(更好):
按此处所述操作:

如果您希望加载环境变量而不以root身份运行,也不向文件中添加dotenv:

$ cd /srv/www/<NAME_OF_YOUR_APP>/current
$ sudo -u deploy -E bundle exec rails console production
$cd/srv/www//current
$sudo-u deploy-E bundle exec rails控制台生产

似乎不起作用。我得到一个关于环境变量丢失的错误。@MattGibson抱歉,我没有使用环境变量支持。我不确定是否有一种优雅的方法可以从那里重用这些食谱。@MattGibson看到了我的答案,它在sudo命令中添加了
-E
。应该加载环境变量。