Wednesday, January 3, 2007

Getting Merb Up And Running

OK. So Merb is the new black. If you're wondering how to use it, well, so am I. So I'm installing it and seeing if I can get it going. Here's a couple stumbling blocks you might see if you're in the same position. (This is all for OS X, btw.)

First, the install instructions here are slightly off. You have to edit dist/conf/merb_init.rb, not conf/merb_init.rb. Very minor distinction. Also, you don't do merb start -t, just merb start; merb doesn't seem to recognize -t any more. These instructions are from October, Merb 0.0.3, and the current version is 0.0.8, so there's no blame in this, btw. I'm not even sure I'm looking at the right page. Anyway, I'm pretty sure the point of -t was some kind of backgrounder, like the equivalent of -d with Mongrel.

Luckily, Merb itself is written in Ruby, and pretty easy to find -- merb-0.0.8/bin/merb -- and it uses the popular and very useful OptionParser library. (Dave Walz-Burkett, who runs the Albuquerque Ruby users' group, uses this all the time, so I've seen it before.) The nice thing about OptionParser is that it's got a very readable syntax and for that reason it's effortless to find the command-line options in Merb.

From reading this, it looks as if the backgrounder option is now -d, like in Mongrel, and the reason is it stands for --daemonize. Depending on your Unix background this will either clarify everything or mean nothing, so, well, hope it helped. Anyway, I made a cool little discovery while I was in there hunting this down. It turns out there's also an -i option. Guess what that's shorthand for? --irb-console. Yup. You can run the whole thing in console mode, just like Rails. Very nice.

Anyway, the next stumbling block, and by the way there are very few, this is a very painless process, but the next one is, having gotten the example app running, it doesn't seem to actually do anything except display a picture of a cute little dog.



Awwwwwwwwwwwwwwwwww.

Cute though this dog is, I know for a fact that displaying its picture is not the upper limit of Merb's capabilities. I know this for two reasons; first, I read a great post on ruby-talk from Ezra Zygmuntowicz, the framework's author, about its purpose -- that is to say, Merb's purpose, not the dog's -- and second, I spoke to him in a conference call with one of my clients about using the framework for parts of my clients' site. Long story short, there's power under the hood here, but either I'm missing something or the example app is really just a "Hello World" so you can say for a fact that your install succeeded.

As far as the power under the hood, basically, Merb means Mongrel plus ERB:

Merb is faster lightweight replacement for ActionPack which is the VC layer for the rails MVC. Merb still uses ActiveRecord for database persistence. But it can also use Og or Mongoose(pure ruby db). It is integrated into mongrel for http serving and has its own controller and view abstraction with sessions filters and erb. It is just a lot smaller and closer to the metal then ActionPack. I wrote it mainly to use in conjusnction with rails applications. To have a small merb app stand in for performance sensative portions of an application.

(From Ezra's post, copied here on my blog.).

Anyway, here's something from the Merb documentation which explains why I'm installing Merb, and what I hope to use it for:

*File uploads* This is one of the things that Merb was written for. Rails doesn‘t allow multiple concurrent file uploads at once without blocking an entire rails backend for each file upload. Merb allows multiple file uploads at once. Start the server and browse to localhost:4000/files/start and you will get a file upload form. This uses the mongrel_upload_progress gem so that must be installed first. There is a very simple upload controller example that handles this upload with a progress bar. When a file is uploaded with Merb, it gets put in a Tempfile. So you just want to copy it to the right place on the filesystem.

And the nice thing about that, it also explains what else the sample app can do. Basically the whole purpose of this is to handle file uploads in a scaleable way. I know the word "scaleable" is not hugely popular in the 37 Signals worldview, but it's something my client needs.

Anyway, this is just an intro, hopefully it's useful.

1 comment:

  1. Hey man. Glad you are checking out the merb. Yeah the sample app is really nothing usaeable. It's just a few little examples of how to use it. I am writing a lightweight blogging engine in merb right now and that will become the sample_app in the next week or so. It will be a much better example of merbs capabilities. Stay tuned.

    -Ezra

    ReplyDelete

Note: Only a member of this blog may post a comment.