MVC
Model
Responsible for maintaining state of the application. May be transient or permanent (i.e stored in a database). It enforces all the business rules that apply to the data. In Rails, things like Validation are handled in the model.
Model is thus both gatekeeper and data store.
View
Generates the user interface, normally based upon data in the model.The view itself never handles incoming data (i.e validation is handled in the model) although it presents ways of inputting data to the user.
There may be many views in an application that access the same model data for different purposes. (user and admin roles on the same data for example).
Code can be used in the view but generally for presentation only.
Controller
Receives events from the outside world, interacts with the model and displays an appropriate view. Because of the way Rails works you can flash messages to the user from the controller.
How this functions in Rails
Incoming requests are first sent to a router, where should the request be sent and how should it be parsed
This identifies an action (a method) somewhere in the controller.
- May look at data in the request that has been made
- May interact with the model
- Invoke other actions
Finally the action will prepare information for the view sent to the user.
Rowan :: Apr.03.2007 :: Uncategorized ::