Skip to content

Instantly share code, notes, and snippets.

@darthneel
Created October 7, 2014 18:45
Show Gist options
  • Save darthneel/a6465729ca4a5f1fa63c to your computer and use it in GitHub Desktop.
Save darthneel/a6465729ca4a5f1fa63c to your computer and use it in GitHub Desktop.
Sample environments.rb for pushing Sinatra + PSQL to Heroku
#These Settings Establish the Proper Database Connection for Heroku Postgres
#The environment variable DATABASE_URL should be in the following format:
# => postgres://{user}:{password}@{host}:{port}/path
#This is automatically configured on Heroku, you only need to worry if you also
#want to run your app locally
require 'active_record'
configure :production, :development do
db = URI.parse(ENV['DATABASE_URL'] || 'postgres://localhost/projecttwo')
ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => db.host,
:username => db.user,
:password => db.password,
:database => db.path[1..-1],
:encoding => 'utf8'
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment