How Does Our Internet Work? A look at our MVC.

Kosi Akporji
3 min readJul 1, 2020

Sooo…we started Ruby on Rails this week at Flatiron School, and man was it a whirlwind!! Can I say this week was short and long all at the same time!!

The first few days were mainly about understanding how the Rails framework all worked together to make a functioning website. To be frank, I almost pulled the hair I had left trying to understand this stuff but thanks to a fellow classmate, he was able to break it down in a way that I could understand!

Almost pulled my hair out

Guess what y’all it actually clicked! So my goal is to try to translate that understanding in this post. Bear with me guys! Still learning here!

Basic MVC Architecture

MVC architecture and how it works on the back end

This is the image that got me on track to begin to understand the Rails framework and how it operates (shout out to Zara for this!). Before we begin lets attempt to define some of these components.

  1. Browser: So when we type a website in our browser, for instance, “www.medium.com”, an HTTP(HyperText Transfer Protocol) request is sent to a server that is far far away but before we get that site it has to go through the steps you see in image above before you actually get to the website returned to you. I’d be lying to you if I knew all of this before Monday, *mind blown!!!* Ok, so we make the request and it goes where? Our router…
Mind Blown!.. gif

2. Router: Well, what exactly is the router? The router pretty much recognizes the URL and sends it to the controller actions, as you can see in the image above. It can also generate your paths and URLs. Now to the controller…

3. Controller: Now we get to the controller which is where the logic for our application lives. The controller fetches the data it needs from the model so that it can respond to the request made by our user. Pretty much, the controller is the middleman between the models and the views (we’ll get to them soon, stay with me!). It makes the model information available to the view so it can display that information to the user. That was a lot I know, hope I haven’t lost ya yet …just stay with me ! Model… here we come!!

4. Models: Our models are pretty much our business folks, they are the dudes in the back crunching the numbers and doing the heavy lifting with joy.

Models is our numbers guy

They are in communication with our database, whatever our controller needs, the model must be ready with that information from the database and return it to our controller. See the model as our chef, though they are running things because without them we won’t be sitting in a restaurant (well, not right now because of CoCo but you get my drift!), they still have to take orders from the waiter aka our controller . They must be ready to serve!! Not to our views…

5. Views: We finally made it to our views page!! We are making some progress y’all! So this is where everything starts to unfold and make sense. The views page carries the logic of what you and I, aka users, get to enjoy. Our views page combines all our logic information and packages it into a nice “HTML string”, gives it back to our controller to render. Now its not yet done, we’re getting too excited! So once its rendered, it makes the HTML look all pretty then it sends it back to the browser for us to bask in the display of our website page…for us to consume and enjoy!

Just take a quick moment, take a nice quick one and look at this page…isn’t it lovely? I think it is, but thats views in a nutshell!

In Conclusion

So there we have it folks! This is pretty much what goes on behind the scenes when we begin to type “www…..” . Doesn’t it make you appreciate the wonders of the internet? I know for me the next time my browser decides to take its sweet old time, I’ll be a bit more gracious because a lot is happening behind the scenes.

Now we’ve figured out the fundamentals lets go ahead and build that first Ruby on Rails project!

--

--

Kosi Akporji

A Pharmacist turned Software Engineer #changethings