
by Mark Kiddell
Although I'm knowledgable in PHP, HTML, MySQL and CGI based web application development, I have never programmed in Ruby nor have I tried Rails before. "Head First - Rails" is introducing me to
a whole new language and method for deploying web applications. Rails claims to allow rapid development of web applications, but how much faster is it?
Before starting with the book, I first had to install both Ruby and Rails, these are both freely downloadable via http://rubyonrails.org/.
There's no need to worry about a web server for serving your pages, once Ruby and Rails have been installed, a local webserver and sqlite3 will also have been automatically installed as well, and they are set to serve only localhost (you sitting at your computer) by default.
After skimming through the introduction - which was very similar to the intro in Head First - MySQL & PHP, I had my first operational Rails web application running in under one hour.
The first application is a basic reservation system that allows you to enter Name, Seat Number, Address, Price paid, Phone number, and Email address for people making ticket reservations. The web app allows both editing and deleting of records.
During my first 45 mins of reading, I had made the web front end, created controllers to control the web back end, and created and populated a database of tickets. In the remaining time the book asks
you to add an extra column to the database for phone number, and asks you to modify the site's front end to allow adding some data to the new column - all this is totally guided by the book and is almost
foolproof. Head First also throws in intentional errors from time to time to make sure you're actually reading the book and not just typing out what it shows and explains.
An experienced PHP and MySQL programmer could have written same basic site in php in under an hour, and it would've been a lot prettier, but as this is the first time I've ever made a Rails app, and I'm doing it following a book, I consider an hour to make a fully functional web app quite fast. I'm sure after a bit of practice the same site could be done in 10 minutes.
One advantage to note for those of us that already create web apps, Rails comes with inbuilt helpers that eliminate insecure input characters.
As the book states, rapid deployment can have advantages and disadvantages. Using the Rails "Scaffold" feature can result in a web app that does way too much - would you really want an auction site where the user can edit his own auctions once a bid has been placed?
Head First moves on to explain that the "scaffold" command used to create the first example provides a barebones operational web app, and this can be broken down by creating model, database with tables, controller, and web views separately - it just requires a bit more work.
This is where Head First flows nicely, it presents a simple solution to get you going, then after it's working it presents a problem. The very next section resolves that problem but at the same time gets a little bit more complicated.
Examples in the first section of the book include:
These "early examples" take you all the way up to page 218 because of the way they show you the application and how to get it working, then keep going back to find ways of making it better and add more features.
At page 219, Chapter 6 begins with the next example, Coconut Airlines. This starts off essentially with the same features as the previous two applications so less help is provided to get the application off the ground initially, just the essentials.
Coconut Airlines makes use of 'Partials', allowing you to split off often used parts of pages into sub-parts - so that they can be rendered into pages as they're needed. This is similar to making use of the 'include' command in php.
The book guides the reader into making a full online seat reservation system which supports multiple users. It presents a more intuitive and interactive site to both staff and passengers using non-standard templates and Ajax libraries, allowing for seat allocations to update automatically on the users web browser without having to refresh the entire webpage constantly. This is quite advanced for what I consider an "introduction to rails" type book.
My biggest complaint up until now is the blandness of all the sites created, they all look pretty much the same, form after form of identical layouts. This obviously can be fixed by modifying the templates manually but it would be nice to see something with a bit of style to finish off.
'Head first Climbers' is the final example in the book. It presents a user interface that fully incorporates Google Maps, it makes use of tables, XML and RSS feeds, has custom pop-up annotations on the map, and even allows the creation of new incidents on the map itself. This is exactly what the book needed to finish off properly.
My overall opinion of the book is that it is well written, it covers all that you'd need to know to be able to make decent database driven applications in minutes. It is also written in the same textbook style as my last review, "Head First - PHP and MySQL" which makes the book both easy to follow, and easy to come back to if you've left it a day or two.
My only reservation is the language itself. Although I can see a lot of advantages, for simple database applications my preference will be to stick to PHP and MySQL as it's far easier to understand code that you've made yourself.
"Head First - Rails" is written by David Griffiths, and is published by O'Reilly.
The book has approximately 450 pages of content and is available at a RRP of £38.50, €40, $49.99.