Skip to content
a middling skeleton of a sinatra app.
JavaScript Ruby
Latest commit db6ada3 Oct 18, 2010 @abachman removed old .gems file
Failed to load latest commit information.
application.rb updated lotsa stuff, mostly documentation Jun 11, 2010

A simple web app skeleton. Uses bundler for dependencies. bundle install gets all.

Hosted at:

Source at:

This is not the simplest possible sinatra app. I left enough loose threads dangling that getting moderately complex sinatra apps up to speed quickly won't be difficult.

To run the application locally, make sure thin is installed (gem install thin), cd into the working directory and run the following command:

$ bundle exec thin start

The application should startup at You can refer to thin's documentation for more configuration options.



Right now it's just database configuration. You'll have to make sure postgres is installed and active on your personal machine for it to run locally.

Because this is a skeleton for me, I want it, if you don't want it, you can safely delete the whole folder.


Static files. Simple enough.

When you're including files from this directory in your html files, you don't need to preface the path with /public. For example, to include a javascript source file that's at public/js/my_source_file.js, you would say:

<script src="/js/my_source_file.js"></script>

public/images/myimg.png would look like:

<img src="/images/myimg.png" />



These are haml templates. Check out for documentation. Erb would also work here if the html style is more to your liking.

To get at the templates, pass the view path relative to the views folder to the haml method in your get block.

get '/' do
  haml :index

If you created a folder inside of views and had a file in it (e.g., views/users/show.haml), it would look like:

get '/users' do
  haml :"users/show"

That's the colon character in front of a string (symbol with a slash in Ruby).

To render a view inside a layout, pass the layout option in:

get '/' do
  haml :index, :layout => :'layouts/default'

Other Files


the source. Define new URL handlers with get or post (delete and put should also work):

get '/form' do
  %{ <form action="/name" method="post">
        <input name="person" type="text">
        <input type="submit">
     </form> }

(the %{ } block returns a string)

For form params, use :variable for the field name and get at them with params[:variable]:

post "/name" do
  "Hello #{ params[:person] }"

To add params to paths, use :whatever in the url string:

get "/user/:id" do
  "You're looking for user with id #{ params[:id] }"

That should be enough to get you started.

No tests. Could not, in the two hours I had, get a simple install of cucumber and rspec to play nicely. I suggest following the Sinatra testing guidelines.

Something went wrong with that request. Please try again.