An examination of the various options for web development with Ruby, including Rails, Ramaze, Camping, Sinatra and Mack. Also includes a look at the heart of all the Ruby web frameworks: Rack.
7. require 'camping'
Camping.goes :Blog
module Blog::Models
class Post < Base; belongs_to :user; end
class Comment < Base; belongs_to :user; end
class User < Base; end
end
Camping module Blog::Controllers
class Index
def get
@posts = Post.find :all
• Microframework (under 4K) render :index
end
end
• Single file applications end
• MVC-ish module Blog::Views
def layout
html do
head { title "My Blog" }
body do
h1 "My Blog"
self << yield
GOTCHAS end
end
• ActiveRecord needed for end
Models def index
for post in @posts
• Markaby needed for Views h1 post.title
end
end
end
8. Sinatra
• Web Application DSL
require 'sinatra'
• Single file applications possible get '/' do
'Hello world!'
• Non-MVC/MVC-ish end
GOTCHAS
• Additional dependencies for
data persistence (Models)
• Additional dependencies for
Views & Templates
9. require 'ramaze'
• Modular Web Framework
class MainController < Ramaze::Controller
• Single file applications possible def index
"Hello, World!"
end
• MVC-ish end
• ORM & Templating Agnostic
Ramaze.start
GOTCHAS
• Less visible community
10. Mack
• Lightweight framework
• Inspired by Rails, Merb and
Ramaze
• Emphasis on speed
• Multithreaded
GOTCHAS
• Limited user community
• Very limited documentation
11. • Everything and the kitchen sink
• The Ruby Web Standard
• Emphasis on “Developer
Happiness”
• HUGE community
GOTCHAS
• Monolithic
• Opinionated
13. • Standard abstraction for web
applications
class HelloWorld
• Super flexible thanks to
def call(env)
[200,
Middleware {"Content-Type" => "text/plain"},
["Hello world!"]]
•
end
Stupid simple end
• Makes your app/framework
web server agnostic
14. Middlewares
• Middlewares are Rack applications that you stack together to form a
larger app
• Rails is composed of numerous pieces of Rack Middleware
• Middlewares respond to call, accept an environment hash and return
a response array
• Examples of Rack Middleware
• Rack::Static - Handles fetching and returning static assets or caches
• Rack::Session::Cookie - Handles your sessions via cookies
• Rack::ShowExceptions - Catches any exceptions thrown in your app
and returns a useful backtrace on the exception.