(The train hasn’t quite left the station.)
Last night I was feeling brave and decided to take the plunge and learn a little about “Ruby on Rails”:http://www.rubyonrails.com/. First step, of course, was to install the needed components.
Following the directions on the RoR homepage, everything went smoothly until I tried to get MySQL hooked up. Although there’s the “Instant Rails”:http://rubyforge.org/projects/instantrails/ package which includes everything preconfigured (Ruby, Rails, MySQL, some Web server or other), I already had MySQL and Apache running (with a live “testbed” site — didn’t want to damage anything here) so I opted for the “manual” install. Besides, it shouldn’t be too hard. After installing various versions of PHP+Apache+MySQL on at least 5 machines, getting everything to work together is sometimes tricky and takes a little troubleshooting, but I’m familiar with the process.
I was able to create and run a “Hello World” app and understand more about what Rails does. Basically, Ruby is just a programming language. I’m not familiar with it so I can’t comment too much about the feel of it yet, but by ASP standards (where by default you have the choice of Visual Basic or JScript), it’s more like Visual Basic: line endings have meaning, you won’t find braces or semicolons lying around anywhere, and also Like Python, indentation level also has meaning. But enough about the language itself; hopefully I’ll be able to comment more about that at a later date.
Rails is simply a set of scripts (written in Ruby, of course) which creates folders and writes out a whole slew of source code and configuration files which form your Web application’s framework. So by the time you start developing, you’re running on a nice framework of code which abstracts routine database operations (typically done tediously through SQL queries) into simple language constructs. Instead of SQL, you just deal with objects in the language.
So in the above sense, there’s no reason for it to be _Ruby_ on Rails. It could have been PHP on Rails or C++ on Rails. It seems the Rails developers had a “thing” for Ruby, and who knows, maybe it _is_ more elegant than other languages out there. I can’t tell you about that yet.
Anyhow, the Ruby interpreter is the same sort of thing as the PHP interpreter. You invoke it from the command prompt with a script as input, and it runs the script. Unlike PHP, it seems that there currently is no Apache module for Ruby. If you want to use it with Apache, it has to get invoked in CGI mode, and you need FastCGI to make that efficient.
Installing Ruby was easy. Next I installed RubyGems, which is a tool written in Ruby for automatically downloading and installing packages (sort of like PEAR from the PHP world, but seemingly more feature-rich.) I issued a command to tell Gems to downloaded and installed Rails, and another command to download and install the MySQL adapter. That’s where something must have gone wrong… since no matter what I did, my application would not connect to the database. It printed this error:
no such file to load -- ./mysql.o
Uninstalling and re-installing the MySQL adapter did not work. Attempting to install different versions of the adapter did not work, since something went wrong during the installation.
This version’s installation worked:
C:\ruby>gem install mysql Select which gem to install for your platform (i386-mswin32) 1. mysql 2.7.1 (mswin32) 2. mysql 2.7 (ruby) 3. mysql 2.6 (ruby) 4. mysql 2.5.1 (ruby) 5. Cancel installation > 1 Successfully installed mysql-2.7.1-mswin32 Installing ri documentation for mysql-2.7.1-mswin32... Installing RDoc documentation for mysql-2.7.1-mswin32...
C:\ruby>
All other versions did not work:
Building native extensions. This could take a while... *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.
...
ERROR: While executing gem ... (RuntimeError)
ERROR: Failed to build gem native extension.
Gem files will remain installed in c:/ruby/lib/ruby/gems/1.8/gems/mysql-2.7 for
inspection.
The folder mentioned immediately above needed to be manually deleted whenever this occurred.
Anyway, that’s as far as I got in a few hours last night. I’ll go fight with this some more, later.