Brief Overview of Ruby on Rails
Ruby on Rails is a framework for the Ruby language, which is used for rapid development of web applications. It does this by allowing you to concentrate on solving your clients’ problems and not getting caught up in building an infrastructure to support your clients problem.
Let’s face it, you don’t want to build database access layer every time you start a new project. Neither will you want to implement a fully functioning MVC pattern on a regular basis. This is the whole point of frameworks; they give you a starting point from which you can build upon. This allows you to concentrate on the clients needs, not the so-called yak shaving tasks, which can hold you back.
A Few Words About MVC
It’s worth mentioning MVC (Model-View-Controller) because it can be one of the factors that discourages people from trying frameworks like Rails. MVC is a relatively advanced programming topic, however, I’m not going to suggest you learn how to implement the MVC pattern, just learn how to make use of it. With this in mind let look what each of the letters in the acronym M.V.C. means and how they fit into web development.
The model layer is where you define classes for the data your application will use/store. For instance, if you want to store posts for a blog, you will have a “Post" model. The model has the capability to interact with the database, to retrieve and store data. This functionality is gained by inheriting it from the ActiveRecord super class. Any methods, which act upon this data, should also be placed in the model.
The view layer has one main purpose - to return the relevant HTML to be rendered on the users browser. In Rail a view is held in an erb (Embedded Ruby) file, which contains both HTML and embedded Ruby statements.
Without the controller, nothing would happen. The controller interacts with the model to retrieve and store data. It will then pass any data, acquired from the model, to the view. The view returns the resulting HTML to the controller and the controller sends this back to the users browser.
This is quite a concise overview of MVC. I highly recommend that you read up on this topic, as it is the key to cracking Rails. This article from betterexplained.com is a great resource for learning MVC in Rails. However, the best way to learn is, install the framework and start playing with it.
This article was written, by me, for Six Revisions - Read More