Coding as a Craft
  • Introduction
    • Learning objectives
  • Your first website
  • ATM Challenge - Ruby basics
    • Step 1
    • Step 2
    • Step 3
    • Step 4
    • Step 5
    • Step 6
    • Step 7
    • Step 8
    • Step 9
    • Step 10
  • Library challenge - Advanced Ruby
    • Important topics
  • Javascript Introduction
    • Variables, objects and arrays
    • Comparisons and Manipulations
    • Javascript Sample Problems
    • Defining Functions
    • Prototypes & Classes
    • Miscellaneous
  • BMI Challenge - JavaScript basics
    • Jasmine - Set up
    • First tests
    • The calculator
    • The Document-Object Model
    • Web interface
    • Acceptance tests
    • Moving on
  • Fizz Buzz in JavaScript
    • NodeJS
  • Checkout challenge
  • Open Weather Challenge
  • SlowFood challenge - OO & TDD
    • Step 1 - Setting up the project
    • Step 2 - Focus on the user experience
    • Step 3 - Entity Relationship Diagrams
    • Step 4 - Implementing the core features
    • Step 5 - Working with the database
    • Step 6 - Working with BDD
    • Extra - Setting up RSpec & Cucumber
  • Ruby On Rails introduction
  • Static Website with Middleman
    • Week lab
    • Setup Middleman
    • HAML - HTML abstraction markup language
    • SASS
    • Accessing data
    • Partials
    • Deploy to Github pages
  • BDD with Rails
    • Exercise - Implement extra features
  • Rails Messaging
    • Working with Legacy Code
    • Tips and Tricks
  • Mid Course Project
    • Project Schedule
  • Going mobile with Ionic
    • Setup
    • Javascript Modules
    • Introduction to Angular
    • Getting to Know Ionic - BMI Challenge
    • Ionic unit and e2e testing
  • The Cooper test challenge
    • The logic
    • The Back-end
    • The Client
    • Connecting the dots
    • Saving and retrieving data
    • Display charts
    • Wrapping up
    • Results tables
  • News Room Challenge
    • Main features
    • Design Sprint
    • Pivotal Tracker
    • Guides
      • i18n with Ruby on Rails
      • Rails 5.2 Scaffold
      • Attachments with Active Storage
      • Encrypted Credentials in Rails 5.2
      • Role-Based Authorization
      • Rendering JSON objects in Rails
      • Testing Ionic Applications
  • SlowFood API - API first or second?
  • Extras
    • Naming Standards
    • Classes vs Modules
    • Code structure
    • Bower
    • Code Review Instructions
    • About README's
    • MVC
    • Three-Tier Architecture
    • Rails Scaffold
    • Tailwind css with Rails
  • Career
    • General Personality
    • Agile Mindset
    • Basic Ruby
    • Advanced Ruby
    • Databases
    • SOLID Principles
  • Sinatra & SlowFood
    • Sinatra - an introduction
    • Start small
    • More Hello World
  • Ember
    • Hello World
Powered by GitBook
On this page
  • Model View Controller
  • The flow of request & response
  1. Extras

MVC

PreviousAbout README'sNextThree-Tier Architecture

Last updated 7 years ago

Model View Controller

Model View Controller (MVC) is a 3-tiered architectural software design pattern for implementing user interfaces. It divides a given software application into three interconnected parts, to separate internal representations of information from the ways that information is presented to or accepted from the user.

In addition to dividing the application into three kinds of components, the MVC design pattern defines the interactions between them.

  • A Model stores data that is retrieved according to commands from the Controller and displayed in the View.

  • A View generates new output to the user based on changes in the Model.

  • A Controller can send commands to the model to update the Model's state. It can also send commands to its associated View to change the it's presentation of the Model.

The flow of request & response

Alright, so you already know the basics of the Request response pattern - the MVC pattern deals with what is happening with the request by your web- and application server and the application itself. At the and, an appropotiate responce is sent back to the client (the browser or whatever has made the request) and forgotten about.

Instead of a sterile “3-tiered architecture” walkthrough, it's more fun to imagine a story with “fat model, skinny controller, dumb view” .

Models do the grunt work, Views are the happy face, and Controllers are the masterminds behind it all.

Think about this flow:

  • The web server (WEBrick, etc.) receives the request. It uses routes to find out which controller to use. The web server then uses the dispatcher to create a new controller, call the action and pass the parameters.

  • Models are Ruby classes extended by ORM methods. They talk to the database, store and validate data, perform the business logic and otherwise do the heavy lifting. They're the chubby guy in the back room crunching the numbers.

  • Views are what the user sees: HTML, CSS, JavaScript, JSON. They're the sales rep putting up flyers and collecting surveys, at the managers direction. Views are merely puppets reading what the controller gives them. They don't know what happens in the back room.

  • Finally, the Controller returns the response body (HTML, XML, etc.) and metadata (caching headers, redirects) to the server. The server combines the raw data into a proper HTTP response and sends it to the client to be presented to the user.

  • The web server is the invisible gateway, shuttling data back and forth (users never interact with the controller directly).

The browser makes a request (such as )

The Controller do the work of parsing user requests (data submissions, cookies, sessions and other “browser stuff”). They're the pointy-haired manager that orders employees around. The best controller is : It gives orders without knowing (or caring) how it gets done.

http://localhost:9292/dish/15
Dilbertesque
Model View Controller