〜Gauche on Railsへの道〜 3. ActiveController 風のものを作る。その6 〜
継続ベースのコントロラーできた! \(^O^)/
通常のWebアプリだと編集画面は、以下のように「変更画面表示」と「変更データの格納」の2つの処理に分かれます。
(define-action edit (set! @todo (find <todo> (params :id)))) (define-action update (update_attributes (find <todo> (params :id)) (params :todo)) (redirect :action 'index))
しかし、継続を使うと下のように1つの処理で書けます。define-continuation 以降が「変更データの格納」の処理です。
ここで、「変更画面表示」で読み出した @todo がセッションのようなもの明示的に使わなくても「変更データの格納」処理に引き継がれているのが、継続のすごいところです。
(define-action edit (set! @todo (find <todo> (params :id))) (define-continuation edit (when (update_attributes @todo (params :todo)) (redirect :action 'index))))
TODO
継続による ControllerRouterパラメター処理ActionController メソッドの追加- ActionView メソッドの追加 ・・・・・ 環境の引き継ぎ、日付select-box
ActiveRecord メソッドの追加モジュールのパスを決定/整理- Rails1.2の仕様に合わせる? (現在、微妙に2.0の仕様が入っている)
- コードジネレータ(Scaffold)