Web App Development: Defining MVC on Ruby on Rails Framework
In the world of development, there are many tools to use in your work including frameworks. Some frameworks are more complete than others. Could it be more complicated? Everything depends on what are you working on.
I’m going to define and cover the basic information about MVC (Model View Controller) and how it is achieved using the RoR framework (Ruby on Rails). So developers can understand it a little bit more so you may choose it as one of your day-by-day developing tool. Additionally, MVC and ROR are tools that I use the most for its simplicity and friendly interface.
Historically, MVC has been used for a long time. It was first implemented by the Smaltalk-80, and now it’s used in almost all GUI frameworks, but we will focus specially on Ruby On Rails.
So what is Ruby on Rails?
Ruby on Rails is, most than nothing, made of two parts. The first one is Ruby, and the second one is Rails (pretty obvious, isn’t it?). Just to follow an order and prevent to mix terms, Ruby is an object oriented programming language, it is used for many purposes, not just web pages, it also used for videogames and desktop apps. The second part is Rails is an open-source web application framework. It is written in Ruby and contains the little tools to make your life easier.
So, we now have clear what is Ruby on Rails. Let’s begin by thinking about three important things that all application must have:
1. When writing applications, you must define a domain. Basically, a domain is what is your application is based on; all your application must be define by the domain. In other words, the domain is modeling your database and defining relationships between items.
2. Next, you must define what can be done by your items that you have already defined on your domain. For example, if in your domain (universe), you define an item called student, now is the time to start thinking what your student can do and can’t do.
3. Finally, it is the time to start thinking about which views can be public available for the domain. Basically, start defining how do your actions that you define in step 2 must look like. So if in step 2, you decided that your students could enroll up into a class. Here is when you said how does this page must look like.
By knowing these three principles, now we can start thinking in MVC language:
Model or ActiveRecord in Rails: This is the place in your application where you must define the relationships, validations and behavior of all the items that are composed by your domain.
Controller or ActionController in Rails: This is an intermediary between the domain and what you defined in step 3, the views. Here is where you define the traffic that is going to happen between defining the domain and the views.
Views or ActionView in Rails: Here is where you code all the views that you defined in step three. This layer is the layer that will be visible for the final user. Also your domain must be reflected with this layer.
So by now you know the basics about MVC in Rails - please don’t be shy and start coding on RoR. I'm sure that you will enjoy it. Thank you for your time and don’t hesitate on leave any comments.
About the Author
Carlos Fabela is a Computer Systems Engineer with more than 2 years of experience on Web/Mobile development. He currently works at iTexico as Web and Mobile Developer.