More Monorail

Trek to Hello World

OK.  I started in on MonoRail today, very minimal code, but it's a start.  The hardest part for me was setting up the bare minimum needed to render a Hello World type page.  I'm a curious individual, and I not a fan of "magic" code and plumbing generated by IDE's.  I wanted to learn what exactly was needed to render content in Monorail.  This forced me to leave out Visual Studio altogether and use only Notepad++.

What Am I Building?

I want to build a website that uses MonoRail obviously, and uses Brail as the view engine.  Why Brail? Why NOT? I don't know any of them and Boo is a weird enough name for a language, how can you not try it out at least?  So Brail it is.  All it needs to do is render a Hello World type page MonoRail-style.

Download Castle Bits

I used Build 518 of the Castle code located here. I've gotten in the habit of just grabbing the latest successful build from their build server to keep up on the latest, you can also just point to the trunk but I'm lazy and just want the last successful build.

My Thought Process

Since I knew nothing about MonoRail, very few details anyway, I figured I walk through the intro.  There's the Getting Started section, which was a quick walk through of stuff.  Next I started sifting through the User's Guide.  Since I'd used the installer for RC2 at some point, I had the Castle MonoRail project wizard installed, so I created a new MonoRail project in Visual Studio.  Of course that worked out of the box, so I tried re-creating the solution by selecting the bits from build 518.  That didn't go so well.  In hind sight there is a change I wasn't aware of, so I think I had recreated it properly but was not up on some of the changes(more on this later).

Since the manual creation of a MonoRail app skeleton in Visual Studio failed, I closed VS and opened Notepad++.  Step 1 was to create a NAnt script to ease the building and rebuilding process from the command line.  Step 2 was to define the structure of the folders, I followed the guidelines from here.  The first go at this, I pretty much used the same code that's baked into the project template, remember, my goal is to just get my first view rendered by MonoRail and that's it.

So here are the exciting pieces so far, we have a controller HomeController.cs, a layout(this is like a master page in web form speak)default.boo, a view(this is like a content page)index.boo, an error view(just a view designated as the view that's gonna get displayed if the controller blows up for some reason)generalerror.boo. (the boo extension is important, I'll explain in just a bit).

OK Houston, Let's Light this Candle!

Armed with my nant script I try to build and one by one eliminate missing but required assembly references.  It built, yay!  Now we need to run it.  I didn't feel like messing around with IIS, so i just opened a new command window, changed dir to where that nant script is and ran nant aspnet on the command line.  This starts a new instance of the webserver that ships with .NET 2.0 on port 6969 pointing to the directory that the nant script was executed from.  So at this point we should be able to type in http://localhost:6969/home/index.rails and voila!

What do we have? YSOD.  That looks something like this.  What gives? Remember I said that that boo extension was important? well apparently it changed from boo to brail, renamed the views to the brail extension and it works like a champ.(so now I have index.brail, default.brail, and generalerror.brail)

I know I said it was a Hello World but they have built in support for Prototype and Scriptaculous, so I couldn't resist throwing a little bit spice on the hello world example.

Get the code for this post here. It includes the needed Castle assemblies so it's about 1.2 mb.

 
Author: , 0000-00-00