merb
DESCRIPTION
An introduction to MerbTRANSCRIPT
MerbAn Introduction
Who am I?
History
Key Focus
Fast(No code is faster than no code)
Memory Efficient
Modular(All you need none you don’t)
As Simple As Possible
Features
Plugins as Gems
Rack Integration
uploader = Proc.new do |env| request = Merb::Request.new(env) if request.path =~ /\/images\/upload/ params = request.params FileUtils.mv params[:file][:tempfile].path, Merb.root / 'public' / 'uploads' / params[:file][:filename]
headers = {"Content-Type"=>"text/html", "Location" => "/images"} [302, headers, "You are being redirected"] else [404, {}, "No Upload here, move along"] end end
merb = Merb::Rack::Application.new
run Rack::Cascade.new([uploader, merb])
File upload example using rack middleware
Router
Optional Path SegmentsMatching match("/articles(/:year(/:month(/:day)))/:title"). to(:controller => "articles", :action => "show"). name(:article) Generating /articles/Hello => { :title => “Hello” } /articles/2008/07/Hello => { :year => “2008”, :month => “07”, :title => “Hello” }
Access to Request & Params
match("/secret").defer_to do |request, params| if request.session.authenticated? params end end
http://www.slideshare.net/carllerche/merb-pluming-the-router-presentation
Controllers
class Posts < Application provides :xml def show @post = Post.get(params[:id]) display @post end end
Background Processing
render_then_call dosend_notification
end
run_later do send_notificationend
Exceptions
class Exceptions < Merb::Controller # handle NotFound exceptions (404) def not_found render :format => :html end
# handle NotAcceptable exceptions (406) def not_acceptable render :format => :html end
end
Merb Slice
Application Server
merb -e produciton -d -c 4
kill HUP ‘master process id’
Processes• master• spawner• worker
Hot Deploy
Questions?