Skip to content

Instantly share code, notes, and snippets.

@nicholalexander
Last active August 29, 2016 20:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nicholalexander/6939646 to your computer and use it in GitHub Desktop.
Save nicholalexander/6939646 to your computer and use it in GitHub Desktop.

Checklist for Heroku/Sinatra/Active Record App Deployment

1. Write your app - YAY!

2. Prepare Your App

  • Set up your environments.rb file

    • mkdir config

    • touch config/environments.rb

    • Set it up thusly:

        configure :production, :development do 
        	db = URI.parse(ENV['DATABASE_URL'] || 'postgres://user@localhost/dbname')
        end
        
        ActiveRecord::Base.establish_connection(
        	:adapter => 'postgresql',
        	:host => db.host,
        	:username => db.user,
        	:password => db.password,
        	:database => db.path[1..-1],
        	:encoding => 'utf8'
        )
      
    • Make sure to include environments.rb in your server.rb

        require_relative 'config/environments'
      
  • ###Add this "after" to your main sinatra server…

      	after do
      		ActiveRecord::Base.clear_active_connections!
      	end
    
  • ###Create your config.ru file…

      	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 install

    • have you seen your nice Gemfile.lock?

  • You need a Procfile!

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

##3. Get Ready to Heroku##

  • git init

  • git commit -m "first commit"

  • create app with heroku apps:create thenameofmyapp or heroku create

  • run schema migration

    • heroku pg:psql
    • create table in database by running schema
  • heroku open and feast your eyes!

Done! Let me know if there is anything missing.

@nicholalexander
Copy link
Author

found an errant "end" in my configure production/development block. fixed it as well as markdown formatting and updated gist.

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