merb-genのサブコマンドには、resource, model, resource_controller, controllerという感じで、リソース版とそうではない版があるようなのですが、 違いが何なのかを調べてみました。

まずはmodel

   1  % merb-gen model foo
   2       (snip)
   3       [ADDED]  spec/models/foo_spec.rb
   4       [ADDED]  app/models/foo.rb

次はresource

   1  % merb-gen resource foo
   2       (snip)
   3       [ADDED]  spec/models/foo_spec.rb
   4       [ADDED]  app/models/foo.rb
   5       [ADDED]  spec/requests/foos_spec.rb
   6       [ADDED]  app/controllers/foos.rb
   7       [ADDED]  app/views/foos/index.html.erb
   8       [ADDED]  app/views/foos/show.html.erb
   9       [ADDED]  app/views/foos/edit.html.erb
  10       [ADDED]  app/views/foos/new.html.erb
  11       [ADDED]  app/helpers/foos_helper.rb

なるほど。resourceの方はRailsのscript/generate resourceのように、 コントローラやViewも作成してくれるようです。

ではcontrollerとresource_controllerの違いはなんでしょうか。 まずはcontroller

   1  % merb-gen controller foo
   2       (snip)
   3       [ADDED]  app/controllers/foo.rb
   4       [ADDED]  app/views/foo/index.html.erb
   5       [ADDED]  spec/requests/foo_spec.rb
   6       [ADDED]  app/helpers/foo_helper.rb

続いてresource_controller

   1  % merb-gen resource_controller foo
   2       (snip)
   3       [ADDED]  spec/requests/foo_spec.rb
   4       [ADDED]  app/controllers/foo.rb
   5       [ADDED]  app/views/foo/index.html.erb
   6       [ADDED]  app/views/foo/show.html.erb
   7       [ADDED]  app/views/foo/edit.html.erb
   8       [ADDED]  app/views/foo/new.html.erb
   9       [ADDED]  app/helpers/foo_helper.rb

なるほど、resourceからmodelを差し引いた感じのものが生成されるようです。 最初から入っているuserモデルのコントローラを生成するのに便利そうですね。

posted by Png genki on Thu 20 Nov 2008 at 13:06

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry1055
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ