Skip to content

Instantly share code, notes, and snippets.

@aitor
Created February 4, 2012 18:25
Show Gist options
  • Select an option

  • Save aitor/1739323 to your computer and use it in GitHub Desktop.

Select an option

Save aitor/1739323 to your computer and use it in GitHub Desktop.
Rails 3.x initializer for loading HEROKU envs in local environment
# Load heroku ENV variables in local development on Rails startup
#
# For a variable defined like this:
#
# heroku config:add S3_KEY='s3krit'
#
# This initializer will define a ENV["S3_KEY"] with a 's3krit' value in development environment.
# Be careful to not overwrite any variable by mistake.
# Potentially destructive.
if Rails.env.development?
require 'heroku/command/config'
app_name = Rails.application.class.parent_name.downcase
heroku_env = Heroku::Command::Base.new.heroku.config_vars(app_name)
# Copy manually. Can't merge since ENV is not a real hash
heroku_env.keys.each do |key|
ENV[key]=heroku_env[key]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment