ソースコードについての解説は http://doruby.kbmj.com/akio0911_on_rails/20080225/_Q_Web__on_Rails に書いておきました。
http://www.nicovideo.jp/watch/sm2432398