Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort.

If you already have a sinatra app, use it or go ahead and create one and add below code which basically has sinatra routes.


#web.rb

  get '/' do
    'Hey there!'
  end

You need a Procfile file alongside your config.ru to tell Heroku how to run your app.

Example content of Procfile

web: bundle exec ruby web.rb -p $PORT

What this says is that run a web process on the port Heroku gives you using the bundle environment.

Sample config.ru

$:.unshift File.expand_path("../", __FILE__)
require 'rubygems'
require 'sinatra'
require './web

run Sinatra::Application
  • Array#unshift will prepend the new path to $:

  • File#expand_path is considered to be Ruby idiom for getting the absolute path to a file when you know the path relative to the current file.

Voila!

Keep Coding !!!

Ameena