MVC – Model

We keep hearing MVC referred to when talking about Rails. But what does it really mean? Over the next three weeks we’ll cover each component in detail.

The M in MVC stands for model.

Every web application that has anything other than very basic functionality will have a database behind it. And every object in our application will be represented by a table in that database.

So, for example, in a shopping website we will need to store information about our products and the customers who buy those products. Each time a Customer buys a Product it will generate a Transaction. This Transaction will also need to be stored in the database. So our database will have (at least) three tables: customers, products and transactions.

A model is that part of your Rails application whose job it is to talk to the underlying database. So, in our Rails application above, we will need to have three models: Customer, Product and Transaction.

When we need to obtain data about any of these three objects, we will ask the relevant model. That model will in turn ask the database.

Check out the next post in the series, MVC – View.

217 thoughts on “MVC – Model

  1. generic cialis from india says:

    Attractive section of content. I just stumbled upon your blog
    and in accession capital to assert that I get actually enjoyed account your blog posts.
    Anyway I’ll be subscribing to your augment and even I achievement
    you access consistently rapidly.

Leave a Reply

Your email address will not be published. Required fields are marked *