In this article I’m going to go over the concepts of ideas of Ruby, it’s not a tutorial on showing you how to make a shopping cart or some other web application/script. The purpose of this article is to give you a base understanding of Ruby on Rails and how it works.
The first thing you have to know about Ruby on Rails is that it’s a framework that’s built on the Ruby programming language; it uses the MVC (Model-View-Controller) architecture. When you think about Ruby you have to think about it as a web application and not a simple script like PHP or Perl.
So, what is this? The MVC is the architecture of how your application works and the way it performs. The whole point of the MVC architecture is for a developer to experience effortless web development by using minimal amount of code and at the same time making their applications efficient.
The Model
The model can simply be said to maintain the state of the application. A model provides the functionality in your application and is the one that contains logical statements, e.g. Should a customer that ordered over 5 products get a 10% discount on shipping?
The View
The view is responsible for creating a user interface based on the models. All it does is gets data from the model(s) and displays it on the screen for the user. E.g. If the customer was entitled to a 10% discount, the view would be responsible for letting the customer know that he/she got a 10% discount as the view would display this message on the screen.
The Controller
The controller is responsible for responding to the user interaction and call the application logic, this means that data is then processed through the Model and then through the View.
This is the path Ruby follows:
- Browser sends a request (Client side).
- The controller receives this request and interacts with the Model (Server Side).
- If there is a database the Model interacts with the database (Server Side).
- The controller invokes the view (Server Side).
- The browser now has a new page displayed due to the View.
That’s basically it! Ruby on Rails is great addition to the web development field, it’s an OOP (Object Oriented Programming) language that’s really easy to use and requires minimal code to get something complex running.
Stay tuned for the next article, I will go over some basics on Ruby on Rails so you can see how the MVC architecture works.