Wednesday, March 10, 2010

Rails MVC

The Model is the application object, the View is its screen presentation, and the controller defines the way the user interface react to user input. Before MVC, user interface designs tended to lump these objects together. MVC uncouples them to increase flexibility and reuse.

The browser makes a request

The web server (mongrel, WEBrick, etc.) receives the request. It uses routes to find out which controller to use: the default route pattern is “/controller/action/id” as defined in config/routes.rb.

Controllers do the work of parsing user requests, data submissions, cookies, sessions and the “browser stuff”.

Models are Ruby classes. They talk to the database, store and validate data, perform the business logic and otherwise do the heavy lifting.

Views are what the user sees: HTML, CSS, XML, Javascript, JSON. They’re the sales rep putting up flyers and collecting surveys, at the manager’s direction. Views are merely puppets reading what the controller gives them. They don’t know what happens in the back room.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.