What is MVC in Ruby on Rails?

后端 未结 8 1667
情深已故
情深已故 2020-12-02 09:06

Could someone please explain MVC to me in Ruby on Rails, in layman terms. I am especially interested in understanding the Model in MVC (can\'t get my head around the model).

8条回答
  •  离开以前
    2020-12-02 09:40

    Here's a brief overview at a high level on how the MVC Pattern works:

    Controller:

    1. Listens on some kind of interaction/event stream.
    2. Controller can send the model that type of interaction/event.
    3. Controller can also communicate with the the view.

    Model:

    1. Models will listen in on the interaction/event from the controller.
    2. Is an abstraction of a data source.
    3. Handles data logic and manipulation.
    4. After it is done with logic, it then sends to controller which will then communicate with the view.

    View:

    1. View can communicate with the controller.
    2. Knows how to render data from the Model to the browser visually.
    3. The Controller tells to View to do something with something from the Model.

    A couple of things to note is that models can't communicate with views directly and vise versa. Only the controller can communicate with the view and model, so the controller acts as the delegator for the interaction/event retrieved from users interaction on the browser.

    check this link for more clear understanding

    one more link to get clear

提交回复
热议问题