Tuesday, August 04, 2009

Get Started with Ruby on Rails on Windows

Well, the first thing you need to know about getting Rails started on Windows is that it sucks. Seriously.

So this weekend I decided to finally having a look at Ruby on Rails and seeing what all the fuss is about. Tried it on my Mac first where in about 5 minutes I was setup and running through the first example from the guide. Today I tried getting it up and running on my Win XP system at work and it took me most of the morning to get it up and running. So 5 minutes vs 2 to 3 hours. Hmmm.

Well to be fair, Ruby does come pre-installed on OS X so setting up rails is simply a matter of typing in "gem install rails" (although I did have to update gems first). On Win XP though I was starting from scratch, and I probably would'nt have found it so annoying if I had'nt experienced the effortlessness of trying it on the Mac first.

So first I installed the latest Windows version of Ruby. That done I went and typed in "gem install rails". Did not work. I'm using a proxy server at work and the gem installer of course didn't pickup the setting from the IE connection settings. Nope you have to run gems by typing it in as "gem install rails --http-proxy http://servername:port"
This of course took a while to figure out as the gem documentation only mentions the http-proxy option but does not tell you that "gem --http-proxy http://servername:port install rails" will not work.
Anyhoo, that done rails seemed to be installed so I started a sample project by typing
rails sample
cd sample
ruby script/server
This started up the test server and I was able to see the default sample page, which led me to believe that Rails was up and running. Not so fast.

I then tried adding a controller by trying script/generate controller home index
I then went to the template file generated, edited it and tried to view the new page--Got an error page instead. Went back to the guide and realised that I had'nt created the Database by doing a "rake db:create", And I promptly got an error when I tried that. By default Rails uses a SQLite database, and the guide has examples for configuring SQLite, MySQL and PostgreSQL databases. Guess what - I had none of these.

What I did have was MS SQL Server 2005. So I tried googling for examples on setting up rails with MSSQL. This did not work. At all. By the way, I should probably mention that I'm not an experienced Ruby guy, and this weekend was the first time I've played around with Ruby, so while there probably is a way to do this, I have no idea what it is.

What I did end up trying next was installing SQLite. The database.yml file in the generated rails app actually had the command required for this - which was "gem install sqlite3-ruby". So I ran this and tried the rake db:create again. And of course it complained about a missing SQLite dll.
Turns out that gem install for sqlite only installs the ruby files for sqlite. Makes sense in hindsight but at the time it was vastly annoying.

So what you need to do to fix this is download the sqlite dll's from here and unzip them to the ruby bin directory. Once I did this Rails finally seemed to be up and running, but I was too tired to actually do any more exploration of it.

Labels: ,