Steps to get a
sinatra/
datamapper site running on
heroku. First do git init in a directory then you need 3 files:
A Gemfile with the gems used, make sure to group them since sqlite isn't available on heroku.
source :rubygems
gem 'sinatra'
gem 'thin'
gem 'haml'
gem 'datamapper'
gem 'dm-postgres-adapter', :group => :production
gem 'dm-sqlite-adapter', :group => :development
A Procfile, simply tells heroku which file to start with, note the -e production to put the site in production mode (in case you load different dependencies depending on environment)
web: bundle exec ruby demo.rb -p $PORT -e production
And a simple Sinatra site
require 'sinatra'
require 'haml'
require 'datamapper'
class Item
include DataMapper::Resource
property :text, String,:key => true
end
configure do
DataMapper.setup(:default, ENV['DATABASE_URL'] ||
"sqlite3://#{Dir.pwd}/demo.db")
DataMapper.finalize
DataMapper.auto_migrate!
Item.create(:text => "hi")
end
get '/' do
@demo = Item.all
haml :view
end
Install
heroku toolbelt, then do the following:
heroku login
heroku create
heroku addons:add heroku-postgresql:dev
heroku pg:promote HEROKU_POSTGRESQL_BROWN
The last command sets the DATABASE_URL environment variable to point to the added postgres instance, the name depends on the added instance type use heroku config to get the correct one. Once all these things are done you can push the site to heroku.
git push heroku origin
For local testing start the site with this command
bundle exec ruby demo.rb
I've put a demo repo for the sinatra site in a github repo
here