Ruby on Rails ~ Basics of MVC and Router ~

Introduction

In this article, I will explain the terms while checking the relationship between MVC (Model, View, Controller) and Router.

What is a Router?

The Router plays a role in determining which function in the application is linked to the URL for which the HTTP request was made. Then, assign one method to the Controller explained next.

Controller

The "Controller" acts as a control tower for the MVC pattern. It is responsible for handling HTTP requests sent by users. The HTTP request is linked from Router to one method of Controller. Then, the Controller creates and acquires a Model corresponding to the HTTP request, passes the acquired value to the View, and performs processing. In other words, it is the job of the Controller to issue commands to the Model and View.

Model

"Model" is an entity that interacts with data. According to the command from Controller, it gets information from the database, updates data, writes data, and erases data. Only Model can interact directly with the database.

View

View defines how the data passed from the Controller will be displayed on the HTML page. This is the web page that will eventually be returned as an HTTP response. The View embeds the appropriate Model selected by the Controller, not just the visual part.

Summary

This is summarized in a series of flows. The Router receives the HTTP request and associates it with the appropriate action. Did the Controller execute that action, instruct the Model or Veiwa, and return the View as an HTTP response?

Recommended Posts

Ruby on Rails ~ Basics of MVC and Router ~
Let's summarize "MVC" of Ruby on Rails
Ruby on Rails basics
Basic knowledge of Ruby on Rails
Basics of Ruby
[Ruby on Rails] Introduction of initial data
[Rails] Addition of Ruby On Rails comment function
part of the syntax of ruby ​​on rails
[Ruby on Rails] Japanese notation of errors
Explanation of Ruby on rails for beginners ①
[Ruby on rails] Implementation of like function
Explanation of Ruby on rails for beginners ⑤ ~ Edit and delete database ~
[Ruby on Rails] Until the introduction of RSpec
Recommendation of Service class in Ruby on Rails
Ruby on Rails Elementary
[Ruby on Rails] A memorandum of layout templates
Ruby On Rails Association
[Ruby on Rails] Individual display of error messages
Ruby on Rails <2021> Implementation of simple login function (form_with)
[Ruby on Rails] Asynchronous communication of posting function, ajax
Implementation of Ruby on Rails login function (devise edition)
Docker the development environment of Ruby on Rails project
[Ruby on Rails] Implementation of tagging function/tag filtering function
Ruby on Rails Refactoring method example summary around MVC
[Ruby] Class nesting, inheritance, and the basics of self
Explanation of Ruby on rails for beginners ⑥ ~ Creation of validation ~
Explanation of Ruby on rails for beginners ② ~ Creating links ~
(Ruby on Rails6) How to create models and tables
Try using the query attribute of Ruby on Rails
Explanation of Ruby on rails for beginners ⑦ ~ Flash implementation ~
[Rails] Introduction of devise Basics
Portfolio creation Ruby on Rails
Ruby on rails learning record -2020.10.04
[Ruby on Rails] Debug (binding.pry)
Ruby on rails learning record -2020.10.05
Ruby on Rails basic learning ①
[Ruby on Rails] about has_secure_password
Ruby on rails learning record-2020.10.07 ②
Commentary on partial! --Ruby on Rails
Ruby on rails learning record-2020.10.07 ①
Cancel Ruby on Rails migration
Ruby on rails learning record -2020.10.06
Ruby on Rails validation summary
Ruby on Rails Basic Memorandum
Explanation of Ruby on rails for beginners ④ ~ Naming convention and how to use form_Tag ~
Ruby on Rails for beginners! !! Summary of new posting functions
[Procedure 1 for beginners] Ruby on Rails: Construction of development environment
[Ruby on Rails] Elimination of Fat Controller-First, logic to model-
(Ruby on Rails6) Display of the database that got the id of the database
Delete all the contents of the list page [Ruby on Rails]
A note about the seed function of Ruby on Rails
[Ruby on Rails] Easy scroll animation of javascript (using ScrollReveal.js)
Explanation of Ruby on rails for beginners ③ ~ Creating a database ~
[Ruby on Rails] Infinite scrolling using gem kaminari and jscroll
[Ruby On Rails] How to search and save the data of the parent table from the child table
Ruby on Rails Overview (Beginner Summary)
Basics of conditional branching and return
[Ruby on Rails] Read try (: [],: key)
Basics of sending Gmail in Ruby
Installing Ruby + Rails on Ubuntu 18.04 (rbenv)
[Ruby on Rails] Introduced paging function