litany against fear

coding with spice ¤ by nick quaranto

RailsConf 2009 And the Greatest of these is Rack Support

published 07 May 2009

This is part of my series of notes on RailsConf 2009. Check them all out here.

This talk is from Ben Scofield.

Lots of awesome stuff is being brought into core: templates, nested attribute assignment, AR::Base#touch, and finally…Rack.

Rack is the Ruby version of Python’s WSGI (Web Server Gateway Interface). Rack apps require a call method that returns a very standardized array with a HTTP status, headers, and the response body. The normal flow of web apps is request, application, and response. Rack allows you to insert middleware between these parts.

Plenty of existing pieces of middleware:

Rack::Profiler: like rubyprof.
Rack::MailExceptions: replacement for exception notifier
Rack::Cache: pretty obvious
Rack::Cascade: enables different Rack apps to serve one whole app. For example, you can have a middleware to do just file uploads.

Going through how Rack is integrated into Rails. You can see the middleware that is loaded by default with rake middleware. Firing up script/server is now done through Rack, and Ben went through the code of how this works.

Metal! Basically a way to load Rack apps inside of Rails easily. The main problem with this: it’s hard to test. You’re forced to mostly use integration tests.

Rack::Bug has debugging info that’s pretty much dropped in, including SQL queries and so on. One gotcha, with middleware it requires a closing body tag.

Caching. Using Metal for progressive caching can really help, and if you can avoid ActionController you can shave a lot of time off the request.

Rack::Embiggener is a simple example of a piece of Metal that lengthens tiny urls. Showing off some code about how this works. Another awesome example: rewriting the hoptoad_notifier in Rack.



code (2) gaming (3) git (9) internet (5) prorubyconf (25) railsconf (17) ruby (10) windows (3)