かずきのBlog

C#やJavaやRubyとメモ書き

目次

Blog 利用状況

ニュース

わんくまBlogが不安定になったため、前に書いてたはてなダイアリーにメインを移動します。
かずきのBlog@Hatena
技術的なネタは、こちらにも、はてなへのリンクという形で掲載しますが、雑多ネタははてなダイアリーだけに掲載することが多いと思います。
コメント
プログラマ的自己紹介
お気に入りのツール/IDE
プロフィール
経歴
広告
アクセサリ

書庫

日記カテゴリ

[NetBeans][Ruby]JRuby on Rails 2.0のscaffold

scaffoldで作られたコードとかを見てると、どうやら1.*系と違う形になってるみたいだ。
試しにrake routesで、どんな風にルーティングが組まれてるかを見てみた。

(in C:/Users/Kazuki/Documents/NetBeansProjects/empmng)
              employees GET    /employees                       {:controller=>"employees", :action=>"index"}
    formatted_employees GET    /employees.:format               {:controller=>"employees", :action=>"index"}
                        POST   /employees                       {:controller=>"employees", :action=>"create"}
                        POST   /employees.:format               {:controller=>"employees", :action=>"create"}
           new_employee GET    /employees/new                   {:controller=>"employees", :action=>"new"}
formatted_new_employee GET    /employees/new.:format           {:controller=>"employees", :action=>"new"}
          edit_employee GET    /employees/:id/edit              {:controller=>"employees", :action=>"edit"}
formatted_edit_employee GET    /employees/:id/edit.:format      {:controller=>"employees", :action=>"edit"}
               employee GET    /employees/:id                   {:controller=>"employees", :action=>"show"}
     formatted_employee GET    /employees/:id.:format           {:controller=>"employees", :action=>"show"}
                        PUT    /employees/:id                   {:controller=>"employees", :action=>"update"}
                        PUT    /employees/:id.:format           {:controller=>"employees", :action=>"update"}
                        DELETE /employees/:id                   {:controller=>"employees", :action=>"destroy"}
                        DELETE /employees/:id.:format           {:controller=>"employees", :action=>"destroy"}
                               /:controller/:action/:id        
                               /:controller/:action/:id.:format

折り返されて見づらいけど、Railsのデフォのルーティングの設定である/:controller/:action/:idのほかにもいっぱい定義がされている。

ルーティングが定義されているroutes.rbを見てみると、見慣れない定義が…

  map.resources :employees

どうやらこれをやると、自動的に色々なルーティングの設定が追加されるっぽい。
/employeesだけでindexメソッドが呼ばれて、/employees/1とかでid=1でshowメソッドが呼ばれ…
HTTPのGET PUT DELETE POSTをうまいこと使うようになってる。

きっとこれが、Rails2.0でRESTスタイルに対応してやりやすくなったぜ!っていうものなんだろうか。
何にせよ、scaffoldで生成されるものが、1.*系と大きく変わったのは間違いないだろう。

単純なCRUDの場合は、こっちのほうが都合よさそうな気がするしね。
仕事で使うわけじゃないから、地道に少しずつやっていこう。

投稿日時 : 2008年5月5日 16:23

Feedback

# welded ball valve 2012/10/18 18:39 http://www.jonloovalve.com/Full-welded-ball-valve-

Only a smiling visitant here to share the love (:, btw great design. "Treat the other man's faith gently it is all he has to believe with." by Athenus.

# ugg sale 2012/10/19 15:01 http://www.superbootonline.com

Regards for helping out, wonderful info. "I have witnessed the softening of the hardest of hearts by a simple smile." by Goldie Hawn.

タイトル
名前
Url
コメント