Wednesday, August 4, 2010

Ruby On Rails

I have not had a great deal of experience with Web development. After having worked with Ruby for a little while I became curious about Ruby On Rails. To learn more about it I follow this tutorial. I had to install specific versions of Ruby (1.8.6) and Rails (2.3.8). They are not the latest versions but they did allow me to learn a little about how Ruby On Rails works.

First of all, Ruby On Rails encourages the use of the Model-View-Controller paradigm. After working through the tutorial and seeing how useful this was I have started thinking about MVC and how it might apply to other software projects. Even if a project does not follow MVC exactly, it certainly won't hurt the developer to keep in mind the separation of data, code and interface.

The tutorial starts by setting up the project (a simple blog) and a database to go with it. The web server is very easy to get running and soon I was on my way. The first thing to do was to take care of the posts. This is where the tutorial introduced scaffolding, With one command Rails can generate a model with associated views and controllers for you. While it is not very pretty, what it produces is quite serviceable. However I was aware of this pragmatic programmer tip:

Don't Use Wizard Code You Don't Understand

So I made sure I read through the tutorial and not just entered the commands when I saw them. The tutorial also pointed out that while it was quick and easy to get a project going this way, most experienced Rails developers will use the wizards selectively to get some of the code generated and doing the rest themselves. I was glad to see Rails made it easy to extract and reuse common code. "Don't Repeat Yourself" (in addition to being another pragmatic programmer tip) is also a guiding principle of Rails.

Once posts were set up the tutorial added comments to the blog project. Instead of using scaffolding, the tutorial used generators to create a model and controller. Creating the controller also produced some skeleton views. I thought I would prefer this method to scaffolding when building my own project. I see scaffolding as an advantage when building a project from a template.

The next part of the tutorial added tags to posts to show how two related models could share a single form.

One other principle behind Rails is the REST (representational state transfer) pattern for Web applications. I have no other frame of reference but it seems to me that this is a very common sense way you to view web applications. I confess to going off on a REST tangent and to liking what I saw.

As I said earlier, I have not done any serious web development work, so I learned a lot from this tutorial. The next step would be to develop a similar project using a different methodology. One of the reasons I like looking at various ways to do similar things is to gain perspective. Should I always use Rails to build a web site? No. I should only use Rails if it is the right tool for the job. But if I only know Rails, I will be forced to use it regardless of whether or not it is appropriate. Hopefully I will be able to allocate some learning time a little later to web development.

Thank-you for reading

No comments:

Post a Comment