A Sinatra and Heroku Application Template in 20 Lines


Posted on

Heroku is a great web publishing platform. Additionally, Sinatra is a great ruby web framework. In this post, I’ll show you how to quickly combine the two.

I have created a sinatra-heroku-template app to make it easy on you. All files combined, it is only 20 lines of code.

Do the following to get it up and running.

git clone git://github.com/scottmotte/sinatra-heroku-cedar-template.git
gem install bundler
bundle
heroku create yourwebapp
git push heroku master
bundle exec heroku open

That’s it. You now have a bare bones Ruby app running in production on Heroku. Add your own code as necessary.

Here’s a breakdown the file structure:

  • app.rb defines your routes and is the core of your application
  • config.ru boots your app
  • Gemfile defines your library dependencies
  • Procfile instructs Heroku how to run your application on its platform

Additionally, you can run the application locally with the following commands

git clone git://github.com/scottmotte/sinatra-heroku-cedar-template.git
gem install bundler
bundle
bundle exec foreman

Visit localhost:5000 and you will see your application running.

Enjoy Sinatra and enjoy Heroku.


Hacker in LA. I believe the future is bright. It's up to us to build it - as programmers we get a big say. Follow me on twitter @motdotla.

Scott Motte on Twitter
Have thoughts on this post?
Chat with us about it on Twitter and Google+