How to Ruby on Rails- MVC Framework

Model-view-controller (MVC Framework) is a software architectural pattern for implementing user interfaces. It divides a given software application into three interconnected parts, Model, View, and controller.  Each of these components is built to handle specific development aspects of an application.

Model-view-controller Architecture

MVC Framework


In Rails, the roles of the model, view and controller are well-defined by the framework, This tutorial explains all of it.

Rail MVC

MVC Framework



The browser makes a request to view a website,


Web server

The web server receives the request. It uses routes to find out which controller to use: the default route pattern is “/controller/action/id” as defined in config/routes.rb.


Model (ActiveRecord)

The model directly manages the data, logic, and rules of the application. Models are Ruby classes. They talk to the database, store and validate data, perform the business logic and otherwise do the heavy lifting. It maintains the relationship between the objects and the database and handles validation, association, transactions, and more.


View (ActiveView)

A view can be any output representation of information, such as a chart or a diagram. Multiple views of the same information are possible, such as a bar chart for management and a tabular view for accountants. Views are what the user sees: HTML, CSS, XML, Javascript, JSON. They’re the sales rep putting up flyers and collecting surveys, at the manager’s direction.


Controller (ActionController).

The controller accepts input and converts it to commands for the model or view.  Receive events from the outside world (usually through views). It interacts with the model. Action controller will display the appropriate view to the user.



When you have code that you use frequently in your views or that is too big to put inside of a view, you can define a method for it inside of a helper. All methods defined in the helpers are automatically usable in the views.

Muhsin Yakkiparamban

Muhsin Yakkiparamban is the co-founder of Lauyou Learning. Muhsin holds Bachelor Degree in Civil Engineering from KMCT Calicut.

You may also like...