Skip to content

Instantly share code, notes, and snippets.

@anoiaque
Created March 15, 2012 17:30
Show Gist options
  • Save anoiaque/2045480 to your computer and use it in GitHub Desktop.
Save anoiaque/2045480 to your computer and use it in GitHub Desktop.
Use ENV to set database connection in rails
#In an initializer
def ENV.[]= key, value
if key == 'RAILS_DATABASE_CONNECTION'
ActiveRecord::Base.establish_connection (JSON.parse(value))
end
store(key, value)
end
ENV["RAILS_DATABASE_CONNECTION"] = %Q{{"database":"foo","adapter":"sqlite3"}} #...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment