CSC/ECE 517 Fall 2013/ch1 1w26 as

From Expertiza_Wiki
Revision as of 16:39, 18 September 2013 by Anish (talk | contribs) (Created page with "Introduction to MVC MVC refers to Model-View-Controller is an architecture pattern applied to separate the user’s view and his interaction with it. It consists of 3 major compo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction to MVC MVC refers to Model-View-Controller is an architecture pattern applied to separate the user’s view and his interaction with it. It consists of 3 major components: The model: The model is the part of the architecture that is connected to the database and contains all the business logic behind the application The view: The view refers to how the user sees any information that he requested for The controller: The controller is the component that co-ordinates between the model and view, making sure that the user gets the data which he had requested for or his given instructions are being executed. This kind of architecture is very popular among web applications.


http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller MVC in Rails To understand how the MVC architecture works in the background, let us take an example of web browsing. The following is the sequence in which the process goes about: 1) The user enters the URL of the page he wishes to visit. 2) The controller interacts with the model to fetch the particular request and invokes the view to render the new view. 3) The view renders the required web page and displays it to the user/client. In Rails, the model, view and controller and separate entities functionally which are knitted together to perform the required functions. Rails follows the philosophy of convention over configuration (expand) In a typical Rails application: 1) Incoming requests are sent to a ‘Router’ which determines where to parse the request and forward it. 2) The request if forwarded to a controller, wherein a particular method/action is called. 3) Using the data available in the request, the action interacts with the model or it causes other action to be invoked. 4) The action then prepares the information for the ‘View’ which renders the output to the user.

Rails handles all the low-level details which would otherwise take so long to do it by self, so that you can concentrate on the application’s core functionality. Two major Rails principles 1) Convention over configuration: By using standard conventions, we can avoid the need for explicit mapping such as deployment descriptors. The naming conventions would automatically perform mapping (like between controller and view)

2) Don’t Repeat Yourself (DRY): While using Rails, we make sure that the required information we might user time and again to execute the same functionality is stored in a single unambiguous place.

Inside Rails 1) Active Record (Model) - 2) Action Pack (View and Controller) – This bundles both the view and controller components which are quite intimate. The controller supplies data to the view and also receives events from the pages generated by the views. VIEW: Action Pack provides View support by helping create either all or part of a page to be displayed in the browser. The dynamic content is generated by templates. CONTROLLER: Coordinates the action between the user, the views and the model. Rails handles most of this functionality behind the scene and lets you concentrate on the application-level functionality. The controller also routes external requests to internal actions, manages caching, manages helper modules and sessions.

k2r3y6p0tex http://www.cs.toronto.edu/~wl/csc309/handouts/rails.pdf