I tried to summarize Ruby on Rails so that a fledgling engineer who has been programming for the first time for 2 months is literally a beginner's point of view and even a beginner can understand as much as possible. I would appreciate it if you could point out any mistakes.
It is an application framework based on Ruby. In the first place, a framework is simply a "framework", a "framework", and a "template", and the basic things needed to create an app are prepared in advance. It's very convenient because it reduces the development cost because you don't have to develop from scratch. Rails Way Rails uses flexible and free Ruby for a kind of fixed rail called a framework, and it can be said that "the good points of the framework" and "the freedom to write your own code" are compatible. Based on this, it is important to think like Rails and write Rails-like code. By doing so, the code will be clean and easy to read, and productivity will naturally increase.
I would like to introduce two typical ones, which are similar to the common philosophy that corresponds to the Rails-like code mentioned above.
DRY (Don't Repeat Yourself) Repeats and duplications are not beautiful as code
__ Convention over configuration __ Instead of writing a large amount of settings as in the conventional framework, it is made simple by hijacking the convention.
Now that we've briefly talked about Rails, let's finish with MVC. MVC is one of the patterns of thinking about how to structure software. Even in an application composed of various processes, the UI (user interface) part has different properties, so if you write it together, the code will be complicated. Therefore, "__ UI related part (view) ", " application-specific processing and data handling (model) ", and " these two bridging behavior (controller) __" MVC (Model View Controller) makes it easier to manage by dividing it into two roles.
There is routing in the controller that acts as a bridge. This is where __ decides which controller (class) and which action (method) is in charge of processing based on the URL or HTTP request received from the browser __. The figure is as follows.
The processing corresponding to each number is explained. (1) Requests from the browser (client) are passed via the web server. (2) Identify the controller and action to be processed based on the URL received by the routing function and call the action. ③ In the action, use the model as needed. (Getting data from the database, etc.) (4) The model also writes and calls to the database as needed. ⑤ Create HTML using the view template corresponding to each action. ⑥ The controller creates a response and returns it to the browser.
This MVC is a very important concept in Rails, so let's understand it well.
Compatible with Ruby on Rails 5 Quick Learning Practice Guide 5.2 that can be used in the field
Recommended Posts