July 28, 2009
Create a Blog in Ruby and Sinatra - Part 1
I decided to write a tutorial about what I learned while writing this blog. We’ll be using Sinatra.
Why not rails?
require 'rubygems'
require 'sinatra'
get '/hi' do
"Hello World!"
end
That’s one reason. The most important thing is, though, that rails makes many decisions for you, and not all of them are good. Using a different framework, specifically one that only handles routing, like Sinatra, allows us to pick our favorite ORM and templating framework. It doesn’t use any magic, so you understand how it works.
Get started with Sinatra
From the sinatra readme
Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort:
# myapp.rb
require 'rubygems'
require 'sinatra'
get '/' do
'Hello world!'
end
Install the gem and run with:
sudo gem install sinatra
ruby myapp.rb
View at: localhost:4567
Play around with it, but it doesn’t take much to start creating a simple web application. I’ll post the rest later!





