Using the Heroku Shared Database with Sinatra and Active Record

ActiveRecord is an amazing (mostly) database-agnostic ORM framework and so it’s a natural choice to use with non-Rails frameworks such as Sinatra. Note that I’ll be using sqlite3 locally but the Heroku Shared Database is a Postgres database so I’ll be setting my environments appropriately. In this post I’ve assumed that you haveĀ a Sinatra app that is working locally and on Heroku. Getting it working locally First up you’ll need a few extra gems in your Gemfile, once again note that I’m using different databases in development, test and production environments. [code language=”ruby”] source ‘http://rubygems.org’ gem ‘sinatra’ gem ‘activerecord’ gem ‘sinatra-activerecord’ # excellent gem that ports ActiveRecord for Sinatra group :development, :test do gem ‘sqlite3’ end group :production do gem ‘pg’ # this gem is required to use postgres on Heroku end [/code] Don’t forget that you’ll need to install the gems using bundler. [code language=”bash”] bundle install [/code] And …

Read more