There has been lately a lot of hype around Ruby on Rails so I decided to find out is there anything behind that hype. First I should start by introducing what is Ruby on Rails!
Ruby is a fully object-oriented interpreted scripting language. It prides on combining the best features from other languages such as Eiffel, Java, Python and Perl. Ruby is natural and easy language and everything is an object no exceptions. Best source for more information about Ruby is the Official Ruby language site.
So what about Rails what is that really?
Ruby on Rails is a web application framework built using ruby as it language. It is open source and promises easy of use and programmer happiness. All Rails applications are built using MVC pattern and its all built-in. When you create a new rails applications it is as easy as issuing
Next thing you might want to do is configure your environment. All you really need is to put in your database name, username, password and host in config/database.yml. Now you can create your model on tables you have. For my example I created a table entries which had columns name, email and message at first. Generating the model from that was as easy as issuing
./scripts/generate model Entry
Notice that the model is singular and the table name is plural. Now that we have a model to work with. Lets create a controller and views for it.
./scripts/generate scaffold Entry
Now you have the basic CRUD operations and views for you to customize and not a single line of code written. Scaffold is a handy little thing that generates all that for you. You can use scaffold also with out generating the code first generating a controller for your model and then inserting scaffold :entry into your controller which would then look like
class EntriesController < ApplicationController
Well that concludes my introductio to rails. You can find more thorough tutorials from the Ruby on Rails website. As a result of this experiment I ended up with a simple guestbook application which I'm making available for everyone to download
Installation of RoR
Next I should probably provide some information about the installation process to by Debian based server. This information might be also useful to my friends whose site I'm hosting on this server.
Since this server is running Debian stable I had to add testing to the apt source.list. Now to make sure my other packages weren't upgraded to testing versions I added following line to my apt.conf
Now installing latest rails was as easy as issuing
aptitude -t testing rails
I also took the latest version of ruby and rake by issuing
aptitude -t testing ruby
aptitude -t testing rake
Next thing is to configure apache. That was also fairly simple task even though I'm using suExec to run CGI. The good thing is that Debian installs ruby in the safe path used by suExec so I'm covered.
SuexecUserGroup username group
Options ExecCGI FollowSymLinks
Allow from all
My rails.javaguru.fi directory is actually a symlink to my guestbook/public directory. Rails generates everything needed to use rails with apache in the public directory of the application. You should never make the application root as your apache document root. That could cause some serious security issues.
I think Ruby on rails lives up to it's expectation but I don't think it will ever replace Java and J2EE. I'm sure it will become more popular over time and it could be a replacement for PHP. I for sure will learn more about ruby and everything I would normally do with php I will from now on do with RoR. Rails to me looks like a web framework with bunch or scripts that automate things. This could well be done with some ant or maven build scripts for a Spring MVC + Hibernate. Perhaps we'll see Spring on Rails some day.