Merb

1,159 views
1,113 views

Published on

An introduction to Merb

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,159
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Merb

  1. 1. Merb An Introduction
  2. 2. Who am I?
  3. 3. History
  4. 4. Key Focus
  5. 5. Fast (No code is faster than no code)
  6. 6. Memory Efficient
  7. 7. Modular (All you need none you don’t)
  8. 8. As Simple As Possible
  9. 9. Features
  10. 10. Plugins as Gems
  11. 11. Rack Integration
  12. 12. File upload example using rack middleware 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 = {quot;Content-Typequot;=>quot;text/htmlquot;, quot;Locationquot; => quot;/imagesquot;} [302, headers, quot;You are being redirectedquot;] else [404, {}, quot;No Upload here, move alongquot;] end end merb = Merb::Rack::Application.new run Rack::Cascade.new([uploader, merb])
  13. 13. Router
  14. 14. Optional Path Segments Matching match(quot;/articles(/:year(/:month(/:day)))/:titlequot;). to(:controller => quot;articlesquot;, :action => quot;showquot;). name(:article) Generating /articles/Hello => { :title => “Hello” } /articles/2008/07/Hello => { :year => “2008”, :month => “07”, :title => “Hello” }
  15. 15. Access to Request & Params match(quot;/secretquot;).defer_to do |request, params| if request.session.authenticated? params end end http://www.slideshare.net/carllerche/merb-pluming-the-router-presentation
  16. 16. Controllers
  17. 17. class Posts < Application provides :xml def show @post = Post.get(params[:id]) display @post end end
  18. 18. Background Processing
  19. 19. render_then_call do send_notification end run_later do send_notification end
  20. 20. Exceptions
  21. 21. 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
  22. 22. Merb Slice
  23. 23. Application Server
  24. 24. merb -e produciton -d -c 4 Processes • master • spawner • worker Hot Deploy kill HUP ‘master process id’
  25. 25. Questions?

×