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モデルのコントローラを生成するのに便利そうですね。