1. Overview of MVC

In this series of lessons, we are going to take a deeper look into how Rails applications work together.

When we were building your Ideator app, we came across words and files that have models, views, and controllers. These three things are extremely important in Rails applications.

Ruby on Rails is an MVC Framework. MVC stands for Model View Controller. The Model, View, and Controller each has seperate responsibilities, but work together in the application:

The Model

The model manages behaviors and data of the application.

Think of the model as the reliable guy who is responsible for fetching information and changing information.

The View

The view is responsible for displaying the user interface. It can show data from the model and display it on the screen for users to see.

In your Ideator application, we wrote a lot of HTML code (in files such as index.html.erb). Notice how index.html.erb is located within the views folder. The views folder typically contains HTML files that contain content for users to see.

The Controller

The controller is the middleman between the model and the view. It is responsible for handling user requests and logic.

Why MVC?

To recap, the Model, View, and Controller each has its own different responsibilities, but work together inside the application. The main benefit of the MVC framework is that since everything has different responsibilities, each component can work independently.

In software engineering, writing code that isn't dependent on other code is an important concept. When we have code that is dependent on another piece of code, then breaking one piece of the code could cause another part of the application to break. Software engineers call code that is independent and reusable "modular code". When engineers talk about "modularity", or keeping the code "modular", they are talking about how code shouldn't be dependent on another piece of code so that it can be reused in other parts of the program.

The purpose of the MVC framework is to keep each component seperate and reusable.

Lesson list