I’ve been busy learning, or at least trying to learn, Ruby on Rails. For people who don’t know this is a new programming language/application which allows programmers, like myself, to create web applications really fast.
At work we have one of our applications written in ASP.NET and since the beginning of last year I have been the unfortunate soul who has to debug and maintain this piece of software. At first I did think that it was pretty good. Towards the end of last year I had an idea to write some web pages linking to a database so that we could store client information, contacts, which clients have what software, what platform they are using etc. Just, more or less, everything that we need to know, all in one place. I felt that this was a good idea so I started writing it. I set-up the database and the tables in SQL Server and started to code the pages having copied chunks of code from our web application. Of course it has never been finished.
Let me warn you that if you work for a software company and one of the managers, who we’ll call Scouse Boy No. 1, buys a Rolodex to store contact information then leave immediately. Just run as far and as fast as you can and don’t look back.
This year I’ve had to convert our ASP.NET application so that it works with the new version of our main software. Even after having ASP training last year it was a slow and tortuous task. The fact that one of the pages doesn’t render correctly in Firefox, that it’s all tied into Microshites® web server and probably doesn’t validate to any W3 standard makes me think that it’s not going to be a possible career path. Maybe if we had spent £500 on Visual Studio things may have been less painful.
So, Ruby on Rails, is just the kind of thing that I’ve been looking for. A development environment written by programmers to make life easier so that more time can be spent writing clean, well structured, code. I ordered the Agile Web Development with Rails book, downloaded the necessary software for Tiger and started to work through a great little Ruby tutorial by Chris Pine. When that was done I started on the book proper, reading through the first section before promptly coming to a grinding halt on page 57. This is when I had a MySQL database and tables created and was about to see the power of Rails for the first time. I must have spent at least 2 days, on and off, trying to figure out why the views of the table weren’t being created. I even un-installed the latest version of Xcode and re-installed the old version from the Tiger DVD, all to no avail. It just wasn’t seeing the database for some reason. Last Saturday afternoon I found the solution. In the
config/database.yml file specify the username, in the book ‘dave’, that you granted database access for. Then re-run the
ruby script/generate scaffold Product admin and you should see
app/views/admin pages being created. Since then I’ve been working through the Book Store application. Everything is so easy, well not exactly easy, but just a joy to use. The scaffold that is generated by Rails knows what the database table looks like so you don’t have to key in lines of HTML with the different types of input code embedded in it. You don’t have to give each field a name, as this is already done for you from the field names. Links for edit/list/show/delete are already created and all the pages behind them. With one Rails command I generated a set of table maintenance pages. This is something that would have taken me at least a few hours using ASP.NET. And all without writing SQL statements.
I think to get the most out of the book you do need to have your own application to work on yourself. It would be really easy to just blindly get the demonstration application working without understanding how the principles can be put into practice. It hasn’t all been plain sailing. Just last night none of the controllers for my application would display in Safari. I found that emptying the cache and deleting any localhost cookies did the trick.