Friday, April 16, 2010

Workshop 2


1. How is Rails structured to follow the MVC pattern?
The Ruby on Rail deals with Model-View-Controller (MVC) framework. The benefits of MVC are isolation of business logic from the user interface, ease of keeping code DRY “Don’t Repeat Yourself “and making it clear where different types of code  belong for easier maintenance.
To know the clearly understand about MVC pattern. We create an application called Blog. We create this by using this command C:\ruby\> rails Blog.
After that two view the root directory steps as follows:-
C:\ruby\> rails Blog.
C:\ruby\> cd blog
C:\ruby\blog> dir
And the directory structure is as follows:-


C:\ruby\blog\app>dir



Models
A model is an object representing data or even activity, e.g. a database table or even some plant-floor production-machine process
.
View
View is some form of visualization of the state of the model.  In Rails, views are often HTML files with embedded Ruby code that performs tasks related solely to the presentation of the data. Views handle the job of providing data to the web browser or other tool that is used to make requests from your application.

Controllers
A controller offers facilities to change the state of the model. In Rails, controllers are responsible for processing the incoming requests from the web browser, interrogating the models for data, and passing that data on to the views for presentation.



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

The model is of a Ruby class to be found in app/models/passenger.rb. The SQL table is passengers – the pluralisation of the model.

The controller method located in app/controllers/passenger_controller.rb. Each controller can access templates to display the input screen and methods for action.

The views are set aside in app/views/passenger/*.rhtml, where each *.rhtml maps to a controller method.

 
 

No comments:

Post a Comment