It was only recently that I FINALLY figured out just what Ruby on Rails is. From most of the posts I saw all I could make of it was “it’s the thing that runs Twitter.” Okay..so what’s it DO?
Well as it turns out, from what I can make of it, Rails is a new web framework designed to streamline web design…BETTER than PHP/ASP/Javscript. So basically it’s a new kind of webserver.
Well I decided that I wanted to try it out. Unfortunately, I don’t run on Linux, and every time I do I get very frustrated. So I decided to try and get it going on Windows (XP to be exact). And I did it! Of course, I had to use an online tutorial (which is fairly outdated by about 2 years) located at All About Ruby on WordPress.
And with a few modifications and updates to the main system, I was able to get it to work as is right now!
And this is as follows:
Install MySQL (or any other SQL engine, but I already have MySQL installed, so that’s nice.)
Install Ruby (I had an old version 1.8.7, so I upgraded to 1.9.3p0. The tutorial says you’d also need to install gems, but I didn’t have to. 1.9.x came with it pre-loaded. The installer for Windows is located at RubyInstaller. I installed to C:\Ruby\ (they recommended C:\Ruby193\, but I might want to upgrade. And what’s next? Ruby194? Ruby200?).
I also made sure I included C:\Ruby\ in the windows path, and associated *.rb files. I also installed the TCL/TK addon, which I doubt I’ll ever need, but hey, it’s America where more is better!
One thing I also noticed later on in the installation was that I needed the optional DevKit located on the same page at RubyInstaller. At the time of this writing, the file is called DevKit-tdm-32-4.5.2-20110712-1620-sfx.exe. Otherwise the “gem” (a friendly name for ruby add-on methods).
The GitHub tutorial states that DevKit was written under MinGW. Now I’m not too happy with Linux frameworks in Windows (MinGW, Cygwin, etc), so I was a little worried that I’d have to install the actual framework. Not so! If you look at the GitHub tutorial, you’ll see it has installing boiled down into three nice easy steps.
Unzip (from 7zip format) into a nice friendly Ruby-Dev folder (I chose C:\ruby-dev\) and navigate in via cmd window. By the way, I’ve learned it’s never good to run ruby scripts from Windows Explorer. If it fails, the resulting command window closes automatically and you never see what’s going on, so it’s better to Start/Run/cmd.exe and navigate in via the DOS window.
Once in the Ruby-Dev directory, you could run ruby dk.rb.
This by itself will just display a help screen with what you’re actually supposed to do.
ruby dk.rb init
This generates a config.yml (a configuration file which in this case just tells the installer where the actual Ruby installation is located). You can open this config.yml in a text editor and see what’s going on. There should be an entry near the bottom that says something like c:/ruby or some such. If this line doesn’t match your Ruby installation, change it so that it does. Remember you only want to go as deep as Ruby’s top-level directory, not “bin” or anything deeper.
Next you run:
ruby dk.rb review
and get to see exactly what it’s going to do based on your config.yml. It’s not too detailed, so you could just skip this step and go straight to:
ruby dk.rb install
It worked for me, even when I did the confirmations listed in the Devkit tutorial on Github, but I won’t tell you how to do that here. You can just read it for yourself (see the link above).
With this done, I could now begin the Rails installation. Remember rails is simply a new way of web developing. Basically, underneath all of the sparkles, it’s nothing more than a webserver. Sure a webserver with a completely new way of writing the actual pages, but a webserver nonetheless.
According to Rails On Windows, you can now install the Rails gem. Remember gems are just add-ons for Ruby, much like you can install Android development kits to implement for the Java language. Except gems are just little default programs that can be called from any other program you write yourself to add functionality.
So anyway, install the Rails gem with dependencies included by running from the command window:
gem install rails --include-dependencies
If all goes well, the script should download all of the gems required to run rails out of the box, plus all of the documentation (ri and rDoc).
Once this is done, you’ll be able to create a new directory for your rails project(s) (I put mine in C:\Rails), navigate there and run:
This will set your project up and hopefully not stall out and crash when it tries to install JSON support (it did when I tried, but that’s why I set up the DevKit detailed before, and after I did, it worked fine).
Once it’s completed and you have received the ‘finished successfully’ message, you can now navigate into that project folder (cd firstproject), and run:
ruby ./script/rails server
Rails will now start up and you should see a few messages such as:
=> Booting WEBrick => Rails 3.1.1 application starting in development on http://0.0.0.0:3000 =>Call with -d to detach =>Ctrl-C to shut down server [2011-11-12 13:17:03] INFO WEBrick 1.3.1 [2011-11-12 13:17:03] INFO ruby 1.9.3 (2011-10-30) [i386-mingw32] [2011-11-12 13:17:03] INFO WEBrick::HTTPServer#start: pid=952 port=3000
It may take a while for all of these messages to appear, but once they have, you can now go into your browser and navigate to http://localhost:3000 and HOPEFULLY see a ‘Congratulations and welcome to Ruby on Rails’ or some such title screen.
That’s the extent of THIS tutorial. I still have yet to figure out how to set up the database and tables and make it all come together that way, but at least I got the server up and running and displaying something nice in my browser!