Take the 2-minute tour ×

I've created a few different "environments" for my app that is hosted on heroku so I have: appName-staging.heroku.com appName-production.heroku.com

I want to use different google api keys for these applications, how do I do this? i've created a google.yml file that looks like:

development: api_key: 'ABCXYZ'

production: api_key: 'DEFXYZ'

so I use ABCSZY when developing locally, and DEFXYZ for appName-production.heroku.com question is, how do i get appName-staging.heroku.com to use a different key?

since every application deployed to Heroku is considered to be in "production", both appName-staging.heroku.com and appName-production.heroku.com use the same key.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You could add a heroku config variable to each environment, allowing you to identify each one from within the app.

Something along the lines of:

$ heroku config:add APP_NAME_ENV=production --app appName-production
$ heroku config:add APP_NAME_ENV=staging --app appName-staging

Then you could grab the current environment from within your app using:


And if you've got your YAML file as a hash called something like GOOGLE_KEYS, the following would return the correct key for a given environment:

share|improve this answer
thanks theTRON, works great! –  Varun Dec 8 '10 at 7:53

Your Answer


