What's the difference between controllers and actions in ruby on rails?

前端 未结 3 1579
误落风尘
误落风尘 2021-02-03 09:57

Can anybody tell me the difference between controllers and actions in ruby on rails?

I fetched this definition from the official rails guide:

A co

3条回答
  •  一生所求
    2021-02-03 11:01

    DISCLAIMER: I don't write code in Rails (never did). I write Sinatra modular applications and use the MVC model.

    You first need to clarify the MVC model. The MVC is an approach to programming web applications (in RoR) or user interfaces in general. So MVC stands for Model-View-Controller. I will try to explain a bit, but in order to understand this, you need to practice and play with it.

    • The Model: If you remove the layers of abstraction, it's your database scheme. The way your application interconnects in order to retrieve information.

    • The View: The way these informations are retrieved elaborated and served. Essentially is what you, or the client, see in the browser.

    • The Controller: The controller is what interacts with the program to produce a requested view or to alter a model. You request a view when you access a chart with statistical information, and you alter the model when you input DATA on it. In Rails ecosystem, ActionController is a class with a set of predefined methods to help you perform easier and quicker standard Controller actions like update a form, etc.

    So the Action Controller allows you to alter data to your models (the db), or request a route to view your data, etc.

    Action is not separated from controllers, it's basically what controllers do :-). Everything else is static.

    If you feel that these concepts are still hard to grasp, try building a very basic modular application in Sinatra, and you will have a ground level view of how things work.

提交回复
热议问题