Jacy Wang

Ruby on Rails Developer/Digital Analyst

Post-it Note: Sinatra

As mentioned in my previous blog, I just built up a simple online Blackjack game based on Sinatra. Here is the link and you can play with it. Sinatra is a DSL to build up web applications quickly in Ruby with minimal efforts. It’s such a great tool that I want to write a post-it note.

Include the gem require 'sinatra' and then gem install sinatra

Routes

1
2
3
4
5
6
7
get '/' do
  ...code...
end

post '/' do
  ...code...
end

Render template

1
2
3
erb :index
# Disable default layout
erb :index, layout: false

Helpers

1
2
3
helpers do
  ...code...
end

Before filter

1
2
3
before do
  ...code...
end

Halt the request

1
halt erb(:index)

For more information, check out its official intro.