Rails Metal, Rack, and Sinatra

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    24 Favorites

    Rails Metal, Rack, and Sinatra - Presentation Transcript

    1. Rails Metal, Rack, and Sinatra Adam Wiggins Railsconf 2009
    2. Show of hands, how many of you...
    3. metal
    4. Show of hands, how many of you...
    5. “The gateway drug”
    6. “The gateway drug”* * it’s a myth, but makes good analogy
    7. Rails Metal is a gateway
    8. Rails Metal is a gateway to the world of Rack
    9. What can you do with Metal?
    10. Replace selected URLs for a speed boost
    11. Example: auction site
    12. Example: auction site
    13. Example: auction site on
    14. Majority of traffic goes to: GET /auctions/id.xml
    15. app/controller/auctions_controller.rb
    16. app/controller/auctions_controller.rb class AuctionsController < ApplicationController def show @auction = Auction.find(params[:id]) respond_to do |format| format.html format.xml { render :xml => @auction } end end end
    17. app/metal/auctions_api.rb
    18. app/metal/auctions_api.rb class AuctionsApi def self.call(env) # implementation goes here end end
    19. app/metal/auctions_api.rb class AuctionsApi def self.call(env) url_pattern = %r{/auctions/(\\d+).xml} if m = env['PATH_INFO'].match(url_pattern) # render the auction api else # pass (do nothing) end end end
    20. app/metal/auctions_api.rb class AuctionsApi def self.call(env) url_pattern = %r{/auctions/(\\d+).xml} if m = env['PATH_INFO'].match(url_pattern) auction = Auction.find(m[1]) [ 200, {\"Content-Type\" => \"text/xml\"}, auction.to_xml ] else [ 404, {}, '' ] end end end
    21. [ 200, {\"Content-Type\"=>\"text/plain\"}, \"Hello, Rack!\" ]
    22. [ 200, {\"Content-Type\"=>\"text/plain\"}, \"Hello, Rack!\" ]
    23. http://www.slideshare.net/adamwiggins/ ruby-isnt-just-about-rails-presentation
    24. An explosion of Ruby projects in the past 2 years
    25. Tests/Specs Web Layer Test::Unit ActionController RSpec Merb Shoulda Sinatra ORM Templating ActiveRecord Erb DataMapper Haml Sequel Erubis Web Server HTTP Client Mongrel ActiveResource Thin RestClient Ebb HTTParty
    26. Tests/Specs Web Layer Test::Unit ActionController ORM Templating ActiveRecord Erb Web Server HTTP Client Mongrel ActiveResource
    27. Tests/Specs Web Layer Test::Unit ActionController ORM Templating ActiveRecord Erb Web Server HTTP Client Mongrel ActiveResource
    28. Tests/Specs Web Layer Test::Unit ActionController RSpec Merb Shoulda Sinatra ORM Templating ActiveRecord Erb DataMapper Haml Sequel Erubis Web Server HTTP Client Mongrel ActiveResource Thin RestClient Ebb HTTParty
    29. Tests/Specs Web Layer Test::Unit ActionController RSpec Merb Shoulda Sinatra ORM Templating ActiveRecord Erb DataMapper Haml Sequel Erubis Web Server HTTP Client Mongrel ActiveResource Thin RestClient Ebb HTTParty
    30. Tests/Specs Web Layer Test::Unit ActionController RSpec Merb Shoulda Sinatra ORM Templating ActiveRecord Erb DataMapper Haml Sequel Erubis Web Server HTTP Client Mongrel ActiveResource Thin RestClient Ebb HTTParty
    31. The world of Rack is now within reach from Rails
    32. Sinatra The classy microframework for Ruby http://sinatrarb.com
    33. require 'rubygems' require 'sinatra' get '/hello' do \"Hello, whirled\" end
    34. $ ruby hello.rb == Sinatra/0.9.1.1 has taken the stage >> Thin web server (v1.0.0) >> Maximum connections set to 1024 >> Listening on 0.0.0.0:4567
    35. $ ruby hello.rb == Sinatra/0.9.1.1 has taken the stage >> Thin web server (v1.0.0) >> Maximum connections set to 1024 >> Listening on 0.0.0.0:4567 $ curl http://localhost:4567/hello Hello, whirled
    36. A minimalist paradise
    37. require 'rubygems' require 'sinatra' require 'lib/article' post '/articles' do article = Article.create! params redirect \"/articles/#{article.id}\" end get '/articles/:id' do @article = Article.find(params[:id]) erb :article end
    38. Sinatra in your Rails app?
    39. Replace selected URLs for a speed boost
    40. Replace selected URLs for a speed boost
    41. Replace selected URLs with Sinatra
    42. app/metal/articles.rb
    43. app/metal/articles.rb require 'sinatra/base' class Articles < Sinatra::Base post '/articles' do article = Article.create! params redirect \"/articles/#{article.id}\" end get '/articles/:id' do @article = Article.find(params[:id]) erb :article end end
    44. Back to the auction example
    45. Back to the auction example
    46. ActionController class AuctionsController < ApplicationController def show @auction = Auction.find(params[:id]) respond_to do |format| format.html format.xml { render :xml => @auction } end end end
    47. Pure Rack class AuctionsApi def self.call(env) url_pattern = /^\\/auctions\\/(\\d+).xml$/ if m = env['PATH_INFO'].match(url_pattern) auction = Auction.find(m[1]) [ 200, {\"Content-Type\" => \"text/xml\"}, auction.to_xml ] else [ 404, {}, '' ] end end end
    48. Sinatra get '/auctions/:id.xml' Auction.find(params[:id]).to_xml end
    49. Sinatra get '/auctions/:id.xml' Auction.find(params[:id]).to_xml end Now that’s what I call minimalist.
    50. The End. http://railscasts.com/episodes/150-rails-metal http://rack.rubyforge.org http://sinatrarb.com http://adam.blog.heroku.com Adam Wiggins Railsconf 2009

    + Adam WigginsAdam Wiggins, 6 months ago

    custom

    3524 views, 24 favs, 7 embeds more stats

    Slides from my Railsconf 2009 talk

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 3524
      • 3080 on SlideShare
      • 444 from embeds
    • Comments 0
    • Favorites 24
    • Downloads 74
    Most viewed embeds
    • 387 views on http://adam.blog.heroku.com
    • 33 views on http://adamblog.heroku.com
    • 8 views on http://ranchero.com
    • 8 views on http://drawohara.com
    • 6 views on http://damon.tumblr.com

    more

    All embeds
    • 387 views on http://adam.blog.heroku.com
    • 33 views on http://adamblog.heroku.com
    • 8 views on http://ranchero.com
    • 8 views on http://drawohara.com
    • 6 views on http://damon.tumblr.com
    • 1 views on http://safe.tumblr.com
    • 1 views on http://scanty-redis.heroku.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories