Merb Generators – Resource, Resource Controller, and Layouts
Merb has some handy generators via merb-gen and I wanted to provide further clarification on a couple of them, merb-gen resource, merb-gen resource_controller, and merb-gen layout.
- Resource Controller – Generates a controller, empty helper file, and associated views. The controller comes with the standard actions index, show, new, edit, delete, create, update, destroy with just the render command in each action.
- Resource – Does the same as the resource controller but adds the model into the equation.
- Layout – With Merb you can generate layout files, the nice thing is that it generates all of the standard html you need such as the doctype declaration, the html frame and catch_content. The merb-gen layout also takes a look at which templating system you are using. For instance if you are using haml, which I highly recommend it will generate the layout in haml instead of erb or regular html.
For resource and resource controller if you have your ORM specified it will fill in all of the regular code that goes along with the typical methods. So for the new action Merb will go ahead and write out everything that is needed for a basic approach to that method. This is a great starting point for your typical controllers but when you need something more custom you might as well go with your standard controller generator.
To destroy any of your generations just rerun the command that you used to generate it and add the -d trigger to the end of your command. This is the mirror of script/generate destroy.
