Skip to content

Instantly share code, notes, and snippets.

@brittlewis12
Forked from nicholalexander/cheatsheet.md
Last active December 25, 2015 07:39
Show Gist options
  • Save brittlewis12/6940187 to your computer and use it in GitHub Desktop.
Save brittlewis12/6940187 to your computer and use it in GitHub Desktop.

Checklist for Heroku/Sinatra/Active Record App Deployment

Prepare Your App

Set up your environments.rb file:

  • mkdir config
  • touch environments.rb
  • set up thusly:
configure :production, :development do
  db = URI.parse(ENV['DATABASE_URL'] || 'postgres://brittlewis@localhost/[dbname_here]')

  ActiveRecord::Base.establish_connection(
    :adapter => 'postgresql',
    :host     => db.host,
    :username => db.user,
    :password => db.password,
    :database => db.path[1..-1],
    :encoding => 'utf8'
  )
end
  • Make sure to require environments.rb in your sinatra server:
require_relative 'config/environments'
  • and add this after block to the server file:
after do
  ActiveRecord::Base.clear_active_connections!
end

Create a your config rackup file

  • touch config.ru
require './server'
run Sinatra::Application

You need a Gemfile!

  • touch Gemfile
  • make it say:
source "https://rubygems.org"
ruby "2.0.0"
gem "sinatra", "~> 1.4"
gem "sinatra-contrib", "~> 1.4"
gem "activerecord", "~> 4.0"
gem "pg", "~> 0.17"

Bundle up

  • bundle install
  • you should see Gemfile.lock created for you

Procfile

web: bundle exec rackup config.ru -p $PORT

Get Ready to Heroku

  • git init
  • git commit -m "first commit"
  • create app
heroku apps:create thenameofmyapp

or...

heroku create

Migrate your schema to Heroku:

  • heroku pg:psql
  • create table in database by running schema
  • heroku open

DONE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment