Wrapping my head around MVC

Alright, I’ll admit it. After a couple of months of trying to wrap my head around Javascript(especially higher order functions, anonymous etc.), I came to the realization that I’m putting the cart before the horse. At least for me anyway. I know there are plenty of people who start out their coding journey with Javascript and everything makes sense. There are also some people like me who have a hard time connecting the Jscript dots and wondering “WTH?”

Hitting that wall led me down the path to start learning Ruby and Rails. It’s been about two months now since I’ve been using Ruby and I’m so glad I made the switch. I agree with many others who say Ruby is much easier to understand if you are a beginner. A bonus…I’m starting to understand Javascript more now also! I’m seeing the bigger picture on using Ruby on Rails, JQuery and Javascript together in the apps I’ve been building at the FirehoseProject.

So what does this have to do with MVC? When I first started app building last month, I didn’t fully understand what was going on with MVC. I was generating migrations, controllers, hooking up this file to that file, etc. My head was swimming a bit on the first app but by the time I was working on the second app, it all started to make sense.

Basically, the Model files handle your data and interact with the Database. The View files are for handling how your app is seen by users. The part I didn’t understand at first was what all the Controller was doing and interacting with. The lightbulb went on when I learned the Controller is handling actions and interacting with both the Model and the View. So when there is a user action on your app, the Controller interacts with the Model to access data and then interacts with the View to display the correct HTML, CSS, Javascript, etc., to the user.

I’m still at the stage where I need to cheat and peek at the lesson instructions to know when to work on the Model, View or Controller files. However, I’m starting to gain more confidence and know how with each passing week. I’m hoping to have the steps down(without cheating) by the end of this month. I’m sure by then I’ll know even more about MVC and I’ll have to come back and edit this post!

For anyone who wants a quick video breakdown of MVC, I recommend checking out this Youtube video(about 3 minutes long). Thanks for reading and happy coding!