Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何检测我的应用程序是否在Heroku上运行?_Ruby On Rails_Heroku - Fatal编程技术网

Ruby on rails 如何检测我的应用程序是否在Heroku上运行?

Ruby on rails 如何检测我的应用程序是否在Heroku上运行?,ruby-on-rails,heroku,Ruby On Rails,Heroku,有没有办法检测rails应用程序是否在Heroku上运行 我想制作一个类似以下的方法: def on_heroku? ... end 您可以通过ENV['var']将自己的设置用于检测 $heroku config:add I_AM_heroku=yes def on_heroku? ENV['I_AM_HEROKU'] end 与公认的答案相比,这有一个优势,即它可以成功地检测到Heroku部署(前提是您正在使用类似Heroku postgres的东西,它将Heroku_POSTGRE

有没有办法检测rails应用程序是否在Heroku上运行

我想制作一个类似以下的方法:

def on_heroku?
...
end
您可以通过
ENV['var']
将自己的设置用于检测

$heroku config:add I_AM_heroku=yes

def on_heroku?
  ENV['I_AM_HEROKU']
end

与公认的答案相比,这有一个优势,即它可以成功地检测到Heroku部署(前提是您正在使用类似Heroku postgres的东西,它将Heroku_POSTGRESQL_COLOR_URL键添加到您的env哈希中),而无需您记住设置环境变量。
def heroku?
  ENV.any? {|x,_| x=~ /^HEROKU/ }
end