Getting started with Merb and Datamapper
Merb is the up-and-coming Ruby web framework, designed to improve upon the ideas in Rails whilst being faster, lighter and less opinionated (or more agnostic). I wanted to discover whether it provides any benefits over Rails and what it does differently. The best way to find out; get it installed it and create a new app.
Update: There’s now a much easier way of getting Merb & DataMapper installed.
The official Merb website gives the following simple installation instructions.
sudo gem install merb
However, since I wanted to also try DataMapper as the ORM those instructions failed to install a working setup due to a conflict between Merb and DataMapper dependencies. Unperturbed, I finally got them both installed and working happily together by getting the bleeding edge code from each project’s github repository and following the instructions provided by Mathew Ford’s Living life on the edge. The book is also available on github, you can contribute patches there. Hopefully this issue will be resolved soon enough so that you’ll be able to install the official release gems for both Merb and DataMapper from Rubyforge (instead of running on edge).
Prerequisites
- You must have git installed (
sudo port install git-coreusing MacPorts on OS X). - Remove any older versions of merb (and datamapper) that you might have installed. Use
gem listto view local gems andsudo gem uninstall <name>to remove each individual gem.
The Easy Way
Matt’s book outlines an easy way of installing the latest merb & datamapper source, however it failed to properly install the DataMapper gem for me so I had to resort to the hardcore approach.
sudo gem install sake
sake -i 'http://edgy.4ninjas.org/edgy.sake'
sake edgy:install packages="merb-stack"
After installing, to keep up-to-date you just need to execute:
sake edgy:update
Now, if you’re hardcore…
Installing the required dependencies
Start by installing the gem dependancies.
sudo gem install rack mongrel json erubis mime-types rspec hpricot mocha rubigen haml markaby mailfactory ruby2ruby
Installing Merb
Download the merb source:
git clone git://github.com/wycats/merb-core.git
git clone git://github.com/wycats/merb-plugins.git
git clone git://github.com/wycats/merb-more.git
Then install the gems via rake:
cd merb-core ; rake install ; cd ..
cd merb-more ; rake install ; cd ..
cd merb-plugins; rake install ; cd ..
Installing DataMapper
git clone git://github.com/sam/extlib.git
git clone git://github.com/sam/do.git
cd extlib ; rake install ; cd ..
cd do
cd data_objects ; rake install ; cd ..
cd do_mysql ; rake install ; cd ..
cd ..
git clone git://github.com/sam/dm-core.git
git clone git://github.com/sam/dm-more.git
cd dm-core ; rake install ; cd ..
cd dm-more ; rake install ; cd ..
Keeping updated
To update your local gems with the latest code changes you’ll need to do a git pull and then rake install for each of the git repositories previously downloaded.
Creating your first Merb app
You create a new empty Merb app via the merb-gen utility.
merb-gen app demo
(You can also create flattened or single file applications if you wish).
merb-gen app app_name --flat (for a flattened application)
merb-gen app app_name --very-flat (for a single file application)
As we’re using DataMapper we need to edit config/init.rb and uncomment the use_orm :datamapper line. The next step is to create the database settings file config/database.yml:
---
development: &defaults
adapter: mysql
database: demo_development
username: demo
password: p@ssword
host: localhost
test:
<<: *defaults
database: demo_test
production:
<<: *defaults
database: demo_production
You can now fire up the Merb server to make sure it runs.
$ merb
~ Loaded DEVELOPMENT Environment...
~ Connecting to database...
~ loading gem 'merb_datamapper' ...
~ Compiling routes...
~ Using 'share-nothing' cookie sessions (4kb limit per client)
~ Using Mongrel adapter
Some other useful commands to know:
merb -i # Interactive merb console
merb-gen model <name> # Creates a Datamapper Model stub
merb-gen resource <name> # Creates a full resource (incuding model, controller, views & test spec)
rake dm:db:automigrate # Perform automigration
rake dm:db:autoupgrade # Perform non destructive automigration
Let’s see how it goes from here with Merb!
Update: There’s now a much easier way of getting Merb & DataMapper installed.
About this entry
You’re currently reading “Getting started with Merb and Datamapper,” an entry on Slash Dot Dash
- Published:
- 07.05.08 / 11pm
- Category:
- Merb

Comments are closed
Comments are currently closed on this entry.