DEV Community

Daniel Todd
Daniel Todd

Posted on

Learning Ruby... any advice?

I am currently attending Le Wagon, and we are working on a food service application for one of our challenges. I am having difficulty understanding fully, the intricacies of an MVC without the utilization of Ruby on rails. Any advice on how I can better understand MVC?

Top comments (2)

Collapse
 
dasheck0 profile image
Stefan Neidig • Edited

I'll try. Basically MVC is an architectural pattern. A way to organise your code in order to make it clearer and the flow more understandable. In every app you have 3 main components. A way the user is interacting with your software (UI), data and business logic. It is up to you to organise it and structure your components. One way to do it is Model-View-Controller (MVC).

Let's start with the View. These kind of components hold your UI logic. Screens, buttons, texts you name it. Their responsibility is to update the user interface components once data changes and notify someone (we'll get to it) when the user does something (i.e. clicking a button, entering something into an input field).

Data is the layer that well interacts with the data. Fetching data (either from an API, Database, Local storage, CSV, whatever) as well as persisting data. Light data processing is usually also part of this layer, like transforming Dtos (Data Transfer Objects) into Application Models (actual data that is used within your app). Lately these kind of components are reactive as it makes it much easier to interact with them and keep the flow maintainable in relations on how to load data from various sources.

Then we need something that connects them. This is where the controller comes into place. Something happens due to a user interaction? The view component should notify the data layer (i.e. a datastore). Controller components do this. The initial data for a screen should be loaded, processed and handed over to the UI? You guessed it. The controller will handle this. Technically speaking this is more MVP than MVC but this would be too much overload.

Tried to keep it simple but probably threw some stuff at you. Maybe google one or two of these terms and you will end up where you need to in order to better understand this. Hope this helps. If not, keep asking :)

Collapse
 
dannyjrt profile image
Daniel Todd

Hello, Stefan and thank you for the reply. I will take your advice, and google my unsure terms. I appreciate your reply and help! MVC is tricky, but it is so much fun to navigate and see the coding art you can create!

Best - Danny