MVC and Me
During my attempt to build my first Ruby on Rails app, I’ve discovered just how painfully ignorant I am about how the MVC architecture works. At first glance (and after finishing Rails for Zombies), I felt I had a solid understanding. I suppose I’m used to the way simple HTML or PHP files function and this layer of complexity that comes with MVC melts my brain.
How I thought I understood it:
- Model = Database
- View = HTML (not a perfect analogy, of course, but similar in that it only displays things)
- Controller = business logic!
Since I’m familiar with PHP, I decided I would try to see how Zend works, since it too uses the MVC architecture. I quickly realized my proto-app was nearly identical to the way my first RoR app looked. So Zend wasn’t the best option for me to try to understand this.
And so I began Googling and ran across some great reading material (links @ the bottom of this post) that helped me to further shape my understanding.
How I now understand it:
- Model = Middleman between the database and the app and the location of business logic (not the controller, as I had thought)
- View = HTML (I think I was actually right!)
- Controller = The "glue" between Models and Views, and the traffic controller (no business logic here!)
Ruby on Rails Beginners’ MVC Links:
- Getting Started with Rails (Always a good place to look for help)
- MVC Demystified: Essence of Ruby on Rails (PPT to walk you through MVC on RoR)
- Creating Your First Ruby on Rails Application From Scratch (I liked the diagram here)