As a programmer new to Ruby who has recently debunked the command line tools issue when starting with Ruby on a Mac you are now ready to begin in earnest your Ruby on Rails or RoR (you know how us Geeks love our acronyms) coding career.
The MVC programming pattern is used in Ruby on Rails and it can be a little confusing if you are new to programming in general or a veteran coder. The acronym M-V-C stands for Model-View-Controller and each has a specific function for your web application.
- Model – Contains application data, logic, rules, functions
- View – The visual representation of said data, rules, logic, etc.
- Controller – Mediator between the Model and View
If that seems a bit abstract to you let’s think of it in another way. View – it’s your eyes. You see what is going on. What do you do with those visual elements? You pass them along your Controller / central nervous system until they get to your Model / brain.
So let’s say that your View is a large, angry looking ferret staring you down with its dark, beady eyes. After your controller has sent that data to your Model it will most likely tell you do adjust your view by turning and moving in a rapid speed in a different direction.
After you have eluded the wily ferret your View is a lovely picnic in front of a pristine lake. Your controller sends this new data to your Model and it decides to sit down and have a delicious avocado sandwich.
Now your view is that you are out of avocado sandwiches (oh no!). So you pass that data along the Controller to your Model which decides to go home (I mean what’s the point if you don’t have avocado right?)
If that analogy didn’t sit well with you perhaps a webpage will. The HTML would be the Model, the CSS the View and the browser the Controller.
This is my long-winded way of telling you that the Model is the data, logic, or information of your program. The View is the visual representation of it and the Controller is the traffic cop that directs them.
Hopefully this helps you understand the MVC pattern a little better and I will be back next month to continue our journey.