A slightly-less simple Sinatra app with reasonable defaults for separate public and view template directories.
Ruby CSS HTML
Pull request Compare This branch is 25 commits ahead of sinatra:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
config
public
spec
views
.gitignore
.ruby-version
Gemfile
Gemfile.lock
README.markdown
config.ru
my_app.rb

README.markdown

Heroku Sinatra MVC

I love Sinatra for writing quick and easy web apps in a snap. I also love MVC for keeping code clear, organized, and easily testable.

This is a template Sinatra app with some MVC-oriented configurations and testing built in.

See the homepage for more details.

Models

Models are located in config/data.rb. For small apps, it's usually convenient enough to just put all models into that file. Though it's easy to separate each model into its own file. See the file for example model structure.

Depending on the database and ORM adapter being used, you may need migrations. Migrations can be found in config/migrations.rb. See the file for example migrations.

This app uses Postgresql for production (to work easily on Heroku), with Sequel ORM, which is similar to ActiveRecord, for those familiar with Rails.

Controller

Sinatra conveniently combines the controller functionality in with the routing. This is all in the usual my_app.rb file.

Views

Each view has its own file in the views directory. This app uses haml for templating, though this can easily be switched out with erb or whatever you want.

Assets

Images, JavaScripts, and CSS are located together in the public directory.

Testing

This app is configured to use RSpec for testing, with tests located in the spec directory.

Getting Started

There is no installation script or magic involved. Just fork this project and start coding.

You might consider adding this fork as a git remote to easily pull down and merge updates with your app:

git remote add template git://github.com/JangoSteve/heroku-sinatra-app.git

Once the app is cloned, run bundle install, and then you can run the specs with bundle exec rspec spec/.

Sample App

For a sample app using this template, see The Aceys.


Here is a sample/template sinatra application ready for deployment to Heroku.

  • Create an acount in seconds at Heroku.
  • Install the gem sudo gem install heroku.
  • If you do not have an SSH key you'll need to generate one and tell Heroku about it
  • Clone this repo git clone git://github.com/sinatra/heroku-sinatra-app [appname]
  • cd /path/to/project
  • heroku create [optional-app-name] (You can rename your app with heroku rename)
  • git push heroku master