Merborial: Getting Started with Merb and DataMapper
Feb 1st, 2008 by Chris Kaukis - Tags: datamapper, Merb, merborial, rails, Ruby
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.
You can leave a response, or trackback from your own site.
[...] Ruby on Rails Website Development Blog from Atlantic Dominion Solutions Merborial: Getting Started with Merb and DataMapper (tags: merb ruby rubyonrails datamapper) [...]
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.[...]…
[...] Ruby on Rails Website Development Blog from Atlantic Dominion Solutions A nice tutorial on getting started with Merb and DataMapper. (tags: Ruby merb datamapper) [...]
[...] 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. [...]
[...] 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. [...]
[...] Merborial: Getting Started with Merb and DataMapper: A tutorial on the very basics, starting with “what to install.” (via Rob Bazinet) [...]
[...] Merborial: Getting Started with Merb and DataMapper (tags: ruby merb mongrel web programming database datamapper) [...]
[...] Merborial: Merbå’ŒDataMapperèµ·æ¥ – 这是Chris Kaukis打算分期写的Merb教程,目å‰å·²ç»å†™äº†ç¬¬ä¸€éƒ¨åˆ†ã€‚这个教程相当新(08å¹´2月)。第一部分里他介ç»äº†å¦‚何安装Merb,DataMapper,和一些其他æ’件,设置Merbåˆå§‹ç¨‹åºï¼Œåˆ›å»ºæ•°æ®åº“,还æä¾›äº†ä¸€äº›æœ‰ç”¨çš„链接。 [...]
[...] 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, [...]
[...] Merborial: Merbå’ŒDataMapperèµ·æ¥ – 这是Chris Kaukis打算分期写的Merb教程,目å‰å·²ç»å†™äº†ç¬¬ä¸€éƒ¨åˆ†ã€‚这个教程相当新(08å¹´2月)。第一部分里他介ç»äº†å¦‚何安装Merb,DataMapper,和一些其他æ’件,设置Merbåˆå§‹ç¨‹åºï¼Œåˆ›å»ºæ•°æ®åº“,还æä¾›äº†ä¸€äº›æœ‰ç”¨çš„链接。 [...]
[...] Merborial: Getting Started with Merb and DataMapper – A simple and straightforward tutorial by Chris Kaukis. [...]
[...] Merborial: Getting Started with Merb and DataMapper – A simple and straightforward tutorial by Chris Kaukis. [...]
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
Or if that link doesn’t work it is here:
http://blog.dynamic50.com/index.php/2008/11/getting-started-with-merb-bundling-merb-with-your-application/
Thanks Jason.
[...] Merborial: Getting Started with Merb and DataMapper – A simple and straightforward tutorial by Chris Kaukis. [...]