Sunday, April 4, 2010

Workshop 2 - Model View Controller design approach

Seeing how the previous workshop went into great detail of the MVC history and design pattern and how it works within Rails. I won't go into great detail of what it is, but only how Rails implements it.

1. How is Rails structured to follow the MVC pattern?

Ruby on Rails is based on the MVC design paradigm (as i said before). It implements this design pattern by breaking up the newly created
application into its separate parts as seen here in the image below: Once you have all the necessary components installed, go to the command line and run rails [projectname] command. This will create a new application directory structure which adheres to the principals of MVC.












As we can see Rails has created a directory call app which contains all the sub-components of the application (i.e. Views, Models, and Controllers). This helps to keep the distinct parts of the application separate, and easier to manage if and when the application becomes big.

























2. Apply the MVC design approach to our Project: Online Taxi Booking System.

To apply the MVC design approach to our Online Taxi Booking System is quite straightforward in Rails. First you need to create the application which was executed in the previous step. Next is to create Views, Models, and Controllers for the application. The way to do this is quite simple by using the command of ruby script/generate scaffold [object] which basically generates each component (i.e. View, Model, and Controller) for the object and places each item in the designated app folder of the projects directory.

As you can see the taxi object was created with all the corresponding model, view, and controller created as well.


No comments:

Post a Comment