Sam Kong
Sam Kong

Reputation: 5810

How to detect if my app is running on Heroku?

Is there a way to detect if a rails app is running on Heroku?

I want to make a method like:

def on_heroku?
...
end

Upvotes: 5

Views: 1758

Answers (2)

user246672
user246672

Reputation:

def heroku?
  ENV.any? {|x,_| x=~ /^HEROKU/ }
end

Upvotes: 5

iltempo
iltempo

Reputation: 16012

You may set your own config vars to use for detection via ENV['var'].

$ heroku config:add I_AM_HEROKU=yes

def on_heroku?
  ENV['I_AM_HEROKU']
end

Upvotes: 7

Related Questions