last update: 2009-05-01 04:55:14 GMT This book is a work in progress; feel free to contribute.
Merb comes with a generator (merb-gen) in order to create Merb applications. The generator can generate different types of Merb applications; to see all of the available generator options, type
$ merb-gen -H
For now, let’s just stick with the types of Merb applications that can be generated.
Merb can be used for anything from very small, quick, single-file applications to large, complex web services. Different application structures can be generated, depending on the developer’s needs. The different application structures you can generate are app, core, flat, and very_flat.
The opinionated Merb stack. This generates a full application directory structure with a full set of configuration files. It also adds a config/dependencies.rb file which includes all of merb-more and DataMapper.
$ merb-gen app my-application
This app has everything needed to start building a first-class web application; it is the most similar to the default structure of Rails. Much of this book will work with the assumption that you have started in this manner.
Run this application by running merb in the application’s root directory. This will start Merb and bind it to the default port 4000. To see your application in action, visit http://localhost:4000/.
Core will generate the full application directory structure with a full set of configuration files. Unlike the app – the opinionated full stack – no dependencies will be added.
$ merb-gen core my-application
Start up this application by running merb in the application’s root directory. Notice that, unlike the other three generated apps, there is no default content in core. Visiting http://localhost:4000/ will generate an error until content and routing are added.
A flat application still keeps all its logic in a single file, but has separate files for configuration and its own view directory.
$ merb-gen flat my-application
Flat applications are run, like any other generated merb app, by running merb in the application’s root directory. By default, all methods in the my-application class will be treated as actions with my-application as the controller. e.g.: http://localhost:4000/my-application/foo
This will call MyApplication#foo and render the output from the foo.html.* template.
A Very Flat application is similar to other Ruby micro frameworks, where the entire application is in one file.
$ merb-gen very_flat my-applcation
To run a very flat application, start up Merb with the following command (within your application directory):
$ merb -I my-application.rb
This will start Merb and bind it to the default port (4000). To see your application in action, visit http://localhost:4000/.