Rails MVC

Giovanny Morales
Jul 28, 2017 · 2 min read

If you want to understand Rails you have to know how rails works using MVC (model, view, controller). this post is going to be a little explanation of MVC using Rails.
Model:
Every model represents a table from the database. The model on our Ruby on Rails application is going to be who maintain the relationship between the objects and the database.
The model is also useful to create different database relation, validations, and scopes.
View:
The view is the part of the application that the users interact with, it is created with HTML, CSS, XML, and others.
Controller:
It is a kind of bridge between the model and the view, every controller is going to be a class and any method like, create, new, index and others, is going to be a view.

To auto generate all of those, You will use scaffold but scaffold is not recommended. It is not recommended because it generate files that you wont need and it could generate a mistakes in the code. I won’t recommend to use it. So, in this case, generate the models, views, and controllers one per one.

How MVC works:
Now is time to know how MVC works. When you interact with the application the browser sends a request. The request arrives at the server and the router decides to which controller to send the request and it is sent to the rails controller then the controller interacts with the model and the controller return the view with the process done.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade