comfort zones are for sleeping

Sunday, August 26, 2007

What to do?

Everything I'm discussing in this post is available at http://www.rubyonrails.org/, but I'll post links to everything in case you're too lazy to click over there yourself. Good goober, it's just one click, you fat load!

What have I done so far to get started on RoR? Nothing. Nada. Zip, zero, zilch. I mean it, not a dern thing. I took like a three-hour nap today, read a chapter of Taran Wanderer by Lloyd Alexander, watched a rerun of America's Funniest Home Videos, and chased after my in-laws' two dogs who are staying with us for the weekend. I love my in-laws dearly, but for some reason our seagrass floor coverings tend to make their dogs incontinent. Oh yeah, and I also ate a piece of cake.

The RoR site makes it seem like you just install a couple of things and, badda-bing badda-boom, you're on the road to fame and fortune. I wonder if getting started with RoR is really as easy as advertised. Now that RoR has been around for a while, I feel like I'm coming in a bit late on the conversation. But all the cool kids are doing it, so off to the RoR download page.

How do I know I've installed RoR correctly?
In order to call myself successful in getting a RoR development environment up and running on my box (a Dell Dimension E512 running Vista Premium), I want to see a functioning editor and compiler for Ruby, and an executing Hello World sample app. To get there, I assume I have to install a few things:

1) Ruby - the language itself.
2) RubyGems - a Ruby 'package manager'.
3) Rails - a Ruby implementation of several really nice patterns, including ActiveRecord.
4) Brick - a Ruby-based webserver. RoR won't run on IIS or Cassini (as far as I know), so you have to install a different webserver.
5) MySql - I don't really have to install this. RoR will indeed work with MS Sql Server. But the lion's share of the most readily available documentation centers on MySql, and it will be much easier later to find a web host for RoR and MySql rather than RoR and MS Sql Server. And since this little adventure is about charting new territory and claiming it for myself: Excelsior!!

There are a few options for getting all this stuff up and running, so I'll follow my typical MO and take the path of least resistance.

Ruby and RubyGems
First I'm gonna use the One-Click Ruby Installer for Windows. I used Version 1.8.5 because they told me to on the download page (they came up with this stuff, I figure they must know what they're talking about), the .exe download. Took all the defaults for installation. It took a few minutes to install, and it installed to c:\Ruby. This took care of items 1) and 2) on my list above.

Rails
And now, I've run into my first problem. To install Rails, the download page says I need to run the following command:

gem install rails --include-dependencies

But where do you run it? Do you just open up a cmd window and type that in? As it turns out: yes, you sure do. But then RubyGems starts asking a number of rather personal questions:

Install required dependency rake? [Yn]
Install required dependency activesupport? [Yn]
Install required dependency activerecord? [Yn]
Install required dependency actionpack? [Yn]
Install required dependency actionmailer? [Yn]
Install required dependency actionwebservice? [Yn]

I answered 'y' to all of these, but it seems a bit odd. I mean, I said 'include-dependencies' in the initial command, and RubyGems is telling me these dependencies are required. Why doesn't it just go ahead and install them without asking permission again? Anyway...after a couple of minutes everything seems to be installed. Or, at least, I'm back to a command prompt. An eerie calm as fallen over my computer.

Next: the Application or the DBMS?
The next step the RoR download page tells me to do is to create the application skeleton. That doesn't seem right - I'm pretty sure the stuff I have just installed didn't include the development webserver, and I'm very sure I haven't installed MySql yet. So let's get MySql installed first. I'll download it from http://dev.mysql.com/.

OK, I pulled this guy: mysql-essential-5.0.45-win32.msi down from dev.mysql.com and installed it. Vista didn't really want to let me, but after some arm twisting MySql is up and running on my box - pretty easy, just run the msi and take the defaults.

Now the Sample Application
So now I'm back to creating a sample app. rubyonrails.org/down tells me to do this:

rails path/to/your/new/application
cd path/to/your/new/application
ruby script/server

I've got no clue here, so I'm switching over to a book by David Heinemeier Hansson (his mother calls him "Hiney"). Hiney says rails is a command-line tool that you use to construct each Rails app you write. According to Hiney, I need to pick out a directory on my machine and use rails to create an app called demo. So I'll make a new directory called c:\rubysandbox and navigate to it in a command shell.

All I have to do to create the app is type rails demo. rails thought about it for a couple of seconds, but then it spit out a bunch of create statements and dumped me back out onto a command prompt. Now when I list the contents of the c:\sandbox\demo there are 14 new directories, plus a Rakefile and a README.

Hiney says there's a directory in there called script, and it contains a ruby script called server. The server script allegedly starts WEBrick - so I guess we did install the web server after all. Here's how you run it: c:\rubysandbox\demo>ruby script/server . Once I run that, I can point Firefox to http://localhost:3000/. When I do, I get a nicely formatted message saying: "Welcome aboard You're riding the Rails!"

Yay me! It worked!!

At this point I expected balloons and confetti to fall from the ceiling, and maybe a buxom spokesmodel would present me with one of those oversized grand prize checks. I'm kind of glad that didn't happen though. I think my wife would be mad. But let's accentuate the positive: I have successfully installed Ruby on Rails, with MySql as the DBMS. And I have proven to myself that my installation is successful, because I've seen the sample app come up in a browser. Very cool! I still have to get the development tools up and running and create a Hello, World! app, but I'll do that tomorrow.

I'm pooped.

2 comments:

Mason Browne said...

Wait until you decide to deploy that sucker. I had a nice two-hour ordeal tonight, two-hour ordeal last night.

Had to:

Install subversion on the live server (took forever... building from source, installing deps from source)

Install subversion on my machine (much easier)

Install mongrel on the server

Install the mongrel_cluster deal on the server (both easy through gems)

Install capistrano on my machine

Set up my project in subversion

Set up my project to feed capistrano its config options

At the same time, get my mongrel clusters set up with a yet-imaginary instance of the current capistrano-app release

Get subversion to properly cache my username and password, as capistrano doesn't allow prompts for it

Get cappy to find my subversion and mongrel_rails on the live server, as they're in /usr/local/bin instead of /usr/local

Figure out why cappy kept dying during the initial cold deployment.

Figure out some of the obscure cappy config options by trolling mailing lists.

Basically, it was a nice cluster f*ck. Thankfully, it's all set up. Yeesh.

dalesmithtx said...

Wow. What a pain in the nether regions. It's going to be a while before I deploy anything. Hopefully there are some 3rd-party hosts out there that make it easy. And cheap.