Wednesday, May 21, 2008

Merb Sherb for Newbies | Part I

Just when I thought I had gotten a good enough handle on Rails, there comes Merb. Well, lets give it a spin, I thought. People I had spoken to (like my friend Peento at mdialog.com or Jarrod at Organic) seemed to think it was great, better than Rails, lighter than Rails etc etc.
So, I decided to give it a spin. First a couple of things:
  • I wont be able to post everything I did in this post for the very simple reason I am not done
  • I also intend this as a tutorial for newbies, who may be struggling with it (just as I did). Well, call me stupid :-) or slow - your pick. If you like this tutorial, please let me know
So, to start off with, hit the site http://merbivore.com .  This is the home page of the Merb framework. A good starting could have been http://wiki.merbivore.com. But it is kinda well, work in progress. however look at the tutorials link. The best tutorial that has ben kept upto date with the frequent changes in the code base is SLAPP
I indeed spent a lot of time going over old articles and tutorials that did not match the current state of merb.

Installation
Pre-requisites: Have Ruby and gem installed - which hopefully you do. Also, have a database installed. I like MySQL, and that is what is going to be used here.

Step 1: Install merb. You can do that using this command line:
$ sudo gem install merb --include-dependencies
This should install Merb. NOTE: As of writing the tutorial, Merb was on version 0.9.3. Things could change fast in the next major release and this tutorial could be useless (unless I update it). 
Now, there are a couple of steps that you should also perform:
$ sudo gem sources -a http://merbivore.com
What this does is add merbivore.com to the list of place gem looks for when searching for updates to gems. Merb is a fast moving project, with lots of changes going in frequently. So,  you may want to do this frequently as well:
$ sudo gem install merb activerecord merb_activerecord merb_helpers rspec merb_rspec
This will make sure the gems required for Merb are installed. Note that Merb supports three different ORM tools. However, I am familiar with ActiveRecord due to my Rails background, and that is what I am making sure in installed.
At this point, you should have Merb installed. 

Step 2: Creating a Skeleton App
This is really simple and close to how you would do it in rails:
$ merb-gen app Helloworld
So there! merb-gen is a generator which does several useful things. Think of it as rails and script/generate in Rails. Now you should a bunch of directories inside the directory HelloWorld. Take a look, poke around. You will see some differences from Rails. The ones I noticed immediately were around lack of model information. No database.yml, no model directory, or migrations stuff. I didn't know whether to be happy or sad. But that we will discuss in the next part when I take the generated app and try and configure it.

2 comments:

jarajago said...

once a geek, always a geek :)
I hope you're earning some moolah by publishing your tutorials. And what's the latest on your book?

Ashish Bansal said...

My book died a gory death...