9 Apr 2009

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

HINT: Begin with a single model, single view and single controller classes. This will give you a head start to the next workshop: Online Taxi Booking System: SQL and Database design

Answer:

Now, I will create a single model, view and controller classes in my home PC. The Diagram-36 shows the Taxi project starts after issuing "rails taxi" command.

Diagram-36 - Taxi project

The Taxi project is created. The I run "ruby script/server" to make the Taxi Project available on the web at tcp port 3000. The Diagram-37 shows the result of running "ruby script/server" command.


Diagram-37 - Taxi Project starts at tcp port 3000

Next, I run "ruby script/generate model Taxi" to generate Taxi Active Record. The Diagram-38 shows the result of running the ruby command. You can find that the taxi.rb file is created. The next Diagram-39 show Taxi class and the related attributes of Taxi class are defined in taxi.rb file.


Diagram-38 - taxi.rb is created (single model)


Diagram-39 - Taxi class is defined in taxi.rb file

In Taxi class, taxinum and taxidrv attributes are defined. They represents taxi number and taxi driver name respectively.

After the single Taxi model (active record) is created, I issue "ruby script/generate controller Taxi" command to create Taxi controller methods in taxi_controller.rb file. The Diagram-40 and Diagram-41 show the taxi_controller.rb is created and the controller methods in taxi_controller.rb file respectively.

Diagram-40 - taxi_controller.rb is created

Diagram-41 - The Taxi controller methods in taxi_controller.rb file

Finally, we can simply use text editor, namely, edit.exe in MS-DOS, to create a view file located in app\views\taxi subdirectory, for example, list method defined in active controller. The diagram-42 shows the view of list method and in fact the list method is displayed as list.rhtml or list.html.erb file (html with embedded Ruby code).

Diagram-42 - list.html.erb (View in MVC approach)

I have applied the MVC design approach to create a single view, controller and model successfully.

No comments:

Post a Comment