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

まずはmodel

pre>>
% merb-gen model foo
(snip)
[ADDED] spec/models/foo_spec.rb
[ADDED] app/models/foo.rb
<<--

次はresource

pre>>
% merb-gen resource foo
(snip)
[ADDED] spec/models/foo_spec.rb
[ADDED] app/models/foo.rb
[ADDED] spec/requests/foos_spec.rb
[ADDED] app/controllers/foos.rb
[ADDED] app/views/foos/index.html.erb
[ADDED] app/views/foos/show.html.erb
[ADDED] app/views/foos/edit.html.erb
[ADDED] app/views/foos/new.html.erb
[ADDED] app/helpers/foos_helper.rb
<<--

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

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

pre>>
% merb-gen controller foo
(snip)
[ADDED] app/controllers/foo.rb
[ADDED] app/views/foo/index.html.erb
[ADDED] spec/requests/foo_spec.rb
[ADDED] app/helpers/foo_helper.rb
<<--

続いてresource_controller

pre>>
% merb-gen resource_controller foo
(snip)
[ADDED] spec/requests/foo_spec.rb
[ADDED] app/controllers/foo.rb
[ADDED] app/views/foo/index.html.erb
[ADDED] app/views/foo/show.html.erb
[ADDED] app/views/foo/edit.html.erb
[ADDED] app/views/foo/new.html.erb
[ADDED] app/helpers/foo_helper.rb
<<--

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

posted by genki genki on Thu 20 Nov 2008 at 12:55 with 0 comments