Here is a short tutorial about getting up and running with the latest Merb (currently 0.5.3) and DataMapper (currently 0.3.0).
Here is the summary of what we will need:
- datamapper – A lightweight ORM
- do_mysql – DataObjects MySQL driver used by DataMapper
- merb – The up and coming Ruby Framework
- merb_datamapper – Plugin for DataMapper
- merb_helpers – A set of helper methods; mainly form helper methods
- merb_has_flash – Unofficial plugin to add a flash session like Rails
There are two ways to install Merb, DataMapper, and it’s dependencies listed above:
- SVN
- GEMS
For this tutorial I am going to use SVN (except for merb_has_flash and the MySQL driver). So, lets get started!
1. Install DataMapper
svn co http://datamapper.rubyforge.org/svn/trunk/ data_mapper cd data_mapper sudo rake gem install
2. Install the DataObjects MySQL driver.
sudo gem install do_mysql
3. Install Merb
svn co http://svn.devjavu.com/merb/trunk merb cd merb sudo rake gem install
4. Install the Merb DataMapper plugin
svn co http://svn.devjavu.com/merb/plugins/merb_datamapper cd merb_datamapper sudo rake gem install
5. Install Merb Helpers plugin
svn co http://svn.devjavu.com/merb/plugins/merb_helpers cd merb_helpers sudo rake gem install
6. (Optional) If you want to have a flash session like in Rails, install the merb_has_flash plugin. Just so you know, this is not an official Merb plugin.
sudo gem install merb_has_flash
Now that Merb is installed we can start a Merb Application.
merb myapp
This will create a directory structure similar to Rails.
1. First thing we need to do is open up the config/dependencies.yml file. In here we will tell Merb to use DataMapper and about the Merb Helpers and Merb Flash plugin. It is pretty straight forward. Just uncomment a single line.
### Uncomment for DataMapper ORM use_orm :datamapper
Next add the following below where it says “Add your other dependencies here”
### Add your other dependencies here dependencies "merb_helpers", "merb_has_flash"
2. Next we should make sure our database is correctly set and created. Create a config/database.yml. It should look something like this:
--- # This is a sample database file for the DataMapper ORM :development: &defaults :adapter: mysql :database: myapp_development :username: root :password: :host: localhost :test: <<: *defaults :database: myapp_test :production: <<: *defaults :database: myapp_production
Next create your database:
mysql -u root create database myapp_development; create database myapp_test; exit
3. Enable sessions by opening up your config/merb.yml and tell Merb to use DataMapper for storing sessions.
# Uncomment if you have more than one ORM or if you need to be specific about # which memory store to use. Built-in options are: memory, cookie, or mem_cache #:session_store: sequel :session_store: datamapper # We added this line
Now create the sessions table.
rake dm:sessions:create
That's it! You have now installed the latest and greatest Merb and DataMapper with all it's dependencies. To update any of the components you downloaded from SVN just go to the directory and type the following:
sudo rake gem install
To run the local development server, just type the following inside your applications directory:
merb
To run the Merb interactive console, just type the following within your applications directory:
merb -i
That should get you at least started and poking around with the Merb framework and DataMapper.
Next, we will go over common Railisms and the Merb equivalents. Look for that in the next day or two.
Links:
http://svn.devjavu.com/merb/trunk
http://svn.devjavu.com/merb/plugins/merb_helpers
http://svn.devjavu.com/merb/plugins/merb_datamapper
http://datamapper.rubyforge.org/svn/trunk/
http://merb.devjavu.com/browser/plugins/merb_datamapper
If you liked this post or any of my other previous posts, please recommend me on Working with Rails.
Other Posts That Might Interest You

