From The Blog

Merborial: Getting Started with Merb and DataMapper

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...

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://merbivore.com/

http://datamapper.org/

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

  1. Merborial: Up and Running with Merb 0.9.0 (dev)
  2. Installing Ruby, Rails, and MySQL on Mac OS X with Macports
  3. Merb is Getting Merged Into Rails 3

Tags: 

  • http://blog.libinpan.com/2008/02/04/links-for-2008-02-04/ links for 2008-02-04 | Libin Pan

    [...] Ruby on Rails Website Development Blog from Atlantic Dominion Solutions Merborial: Getting Started with Merb and DataMapper (tags: merb ruby rubyonrails datamapper) [...]

  • http://web2announcer.com/go/2404261 Web 2.0 Announcer

    Merborial: Getting Started with Merb and DataMapper…

    [...]A tutorial that walks you through getting started with Merb and DataMapper, and creating a basic Merb application.[...]…

  • http://rbazinet.wordpress.com/2008/02/04/links-for-2008-02-04/ links for 2008-02-04 « Accidental Technologist

    [...] Ruby on Rails Website Development Blog from Atlantic Dominion Solutions A nice tutorial on getting started with Merb and DataMapper. (tags: Ruby merb datamapper) [...]

  • http://www.rubyinside.com/merb-tutorials-and-resources-716.html 21 Merb Links, Tutorials and Other Resources

    [...] Merborial: Getting Started with Merb and DataMapper – Chris Kaukis with the first installment of a very up to date Merb tutorial (February 2008). In this installment, he shows how to install Merb, DataMapper, and some other plugins, sets up an initial Merb application, creates a database, and provides a bunch of links to useful resources. [...]

  • http://rbazinet.wordpress.com/2008/02/14/good-merb-and-datamapper-tutorial-from-atlantic-dominion-solutions/ Good Merb and DataMapper Tutorial from Atlantic Dominion Solutions « Accidental Technologist

    [...] I have found a blog over at Atlantic Dominion Solutions that provides some good information on using some of the latest coming from the Ruby world.  One such nugget was an article by Chris Kaukis titled Merborial: Getting Started with Merb and DataMapper. [...]

  • http://afreshcup.com/?p=790 A Fresh Cup » Blog Archive » Double Shot #144

    [...] Merborial: Getting Started with Merb and DataMapper: A tutorial on the very basics, starting with “what to install.” (via Rob Bazinet) [...]

  • http://zhesto.wordpress.com/2008/02/19/links-for-2008-02-19/ links for 2008-02-19 « Bloggitation

    [...] Merborial: Getting Started with Merb and DataMapper (tags: ruby merb mongrel web programming database datamapper) [...]

  • http://blog.myess.cn/2008/03/21ge-guan-yu-merbde-lian-jie-jiao-cheng-he-qi-ta-zi-yuan-385.html 21个关于Merb的链接、教程和其他资源 – MyEss.cn

    [...] Merborial: Merbå’ŒDataMapperèµ·æ­¥ – 这是Chris Kaukis打算分期写的Merb教程,目前已经写了第一部分。这个教程相当新(08å¹´2月)。第一部分里他介绍了如何安装Merb,DataMapper,和一些其他插件,设置Merb初始程序,创建数据库,还提供了一些有用的链接。 [...]

  • http://docecosas.com/blog/datamapper-en-ruby doce cosas : DataMapper en Ruby

    [...] que para proyectos Ruby que no sean Rails puede ser una interesante opción, sobre todo si estamos probando algo como Merb con DataMapper. Publicado el Lunes, 2 de Junio, 2008, a las 10:06 pm. Etiquetado como programación, rails, [...]

  • http://123e.org/digest_450.html 21个关于Merb的链接、教程和其他资源 – 英文ç«

    [...] Merborial: Merbå’ŒDataMapperèµ·æ­¥ – 这是Chris Kaukis打算分期写的Merb教程,目前已经写了第一部分。这个教程相当新(08å¹´2月)。第一部分里他介绍了如何安装Merb,DataMapper,和一些其他插件,设置Merb初始程序,创建数据库,还提供了一些有用的链接。 [...]

  • http://www.rubyinside.com/44-merb-resources-1318.html Merb 1.0 Released So Here’s 44 Links and Resources To Get You Going

    [...] Merborial: Getting Started with Merb and DataMapper – A simple and straightforward tutorial by Chris Kaukis. [...]

  • http://turnings.phrasewise.com/2008/11/09/merb-10-released-so-here%e2%80%99s-44-links-and-resources-to-get-you-going/ Merb 1.0 Released So Here’s 44 Links and Resources To Get You Going « turnings

    [...] Merborial: Getting Started with Merb and DataMapper – A simple and straightforward tutorial by Chris Kaukis. [...]

  • http://www.dynamic50.com/ Jason Green

    Hi Chris,

    Thanks for your article. Really helpful.
    I have written a more up to date getting started with merb and datamapper using thor tasks to bundle it all in here: http://blog.dynamic50.com

    Jason

  • http://www.dynamic50.com Jason Green

    Hi Chris,

    Thanks for your article. Really helpful.
    I have written a more up to date getting started with merb and datamapper using thor tasks to bundle it all in here: http://blog.dynamic50.com

    Jason

  • http://www.dynamic50.com/ Jason Green
  • http://www.dynamic50.com Jason Green
  • http://www.techcfl.com/ Robert Dempsey

    Thanks Jason.

  • http://www.techcfl.com Robert Dempsey

    Thanks Jason.

  • http://fuuygfjkkjg.zteo.com/2008/11/24/merb-10-released-so-here%e2%80%99s-44-links-and-resources-to-get-you-going/ Merb 1.0 Released So Here’s 44 Links and Resources To Get You Going

    [...] Merborial: Getting Started with Merb and DataMapper – A simple and straightforward tutorial by Chris Kaukis. [...]

blog comments powered by Disqus