1. Set up a focus group (like a study group for peer learning) to work on the Ruby on Rails workshops via Interact tools as a class.
I setup a focus group that work on Ruby on Rails at: http://railsfocusgroup.blogspot.com, and had invited our classmates to join by personal email. The link of the blog was also posted on CSU Forum.
2. What is meant by “convention over configuration” and how does it reduce coding?
A Web application is composed by many parts in different ways. If we have a variable named picture in a computer program, and have a column named image in the database table. The computer retrieves data from the image table column and stores the data in picture variable. Then the program performs some acrobatics with the picture variable's data. the programmer tie-up the picture and image together using a configuration file. The configuration file encodes facts such as "variable picture reads data from column image". Programmer spend time to write the configuration files and specifying complex chains of names. Finally, errors creep into the system, and programmers spend more times fixing bugs (Burd 2007).
In Rails, a variable named image matches automatically with the column of the same name in the database table. A variable named Picture matches automatically with a table named pictures (in plurals form). And a variable named Person matches automictically with a table named people (Rails understands plurals) (Burd 2007).
3. Further work on understanding MVC:
a. See the wiki at http://wiki.rubyonrails.org/rails/pages/UnderstandingMVC
The page doesn't exist.

b. Do the MVC tutorial at http://wiki.squeak.org/squeak/1767
Summary after my reading:
MVC has been the easrliest and most successful design patterns since 1979 by Trygve Reenskaug. MVC paradign the user input, the modeling of database, and visual feedback to users are handled by 3 types of object separately:
- View - manages the graphical and textual output to the display
- Controller - interprets the mouse and keyboard inputs from users, controlling the model and the view to change appropriate
- Model - manages the behavior and data, responds to requests and instructions.
The video is about 1 hour 15 minutes long. It is the Part 1 of Ruby on Rails short course that conducted by RAD Lab, University of California, Berkeley. The title of the Part 1 is 'Hello World'. The speaker is Armando Fox. Armando reviewed and introduce:
- Web apps of the Rail
- How MVC design pattern work in Rails
- SQL operations (Create, Read, Update and Destroy)
- Convention over configuration
- Hello World program
- Some programming technique demo in Rails
The article is a chapter come form the book Essential Action Script 2.o which written by Colin Mock, issue by O'Reilly's. The article explains the concept of the Model-View-Controller (MVC) Design pattern.
The MVC design pattern separates user interface code into 3 distinct classes:
- Model - store the data and application logic for the interface
- View - Renders the interface (usually to the screen)
- Controller - Responds to user input by modifying the model
- In the same information (model) allows multiple representations (views)
- At both compile time and runtime allows user interfaces (views) to be easily added, removed or changed
- At both compile time and runtime allows response to user input (controller) to be easily changed.
- Advance for reuse
- Multiple developers update interface, logic or input of an application without affecting other source code at the same
- Developers can focus on a single job of the application at a time
- Model - stores data in properties and provides application-specific methods that set and retrieve that data. The data-management methods are not generic, they are customized in each application and must be known to the controller and the view.
- View - create user interface and keep it up-to-date. The view monitor the state changes in the model. If change occur, the view updates the interface to reflect the change.
- Controller - monitor for notifications from the view, based on user input and translates the input into changes in the model. The controller sometime makes logical decisions about the input before making the corresponding change to the model.
1. How is Rails structured to follow the MVC pattern?
Ruby on Rails fully apply the MVC framework, Rails divides the work of an application into Model, View and Controller separately. MVC work in closely cooperative subsystems. Coding in Rails do separately in different sub folders for MVC pattern. Writing code can be done by different programmers, but they are working together for the same application.
Model (ActiveRecord) - Maintenains the relationship between objects and database. It handles validation, association, transactions and etc. ActiveRecord library implemente this subsystem, which provides an interface and binding between the tables and Ruby program code. Ruby method names are automatically generated from the field name of the database tables.
View (ActionView) - presentation of data in particular format, called by the decision of a controller to present data. They are script based very easy to integrate with AJAX technology. This subsystem is implemented in ActionView folder which is embedded Ruby based system, define presentation templates for data presentation. The display of a view in an application respesent the results.
Controller (ActionController) - directs traffic within an application, query the models for specific data and organize data such as searching, sorting and massaging it, into a form that fits the needs of the view. This subsystem is implemented in ActionController which is the connector between ActionRecord and ActionView.
2. Apply the MVC design approach to our Project: Online Taxi Booking System.
The workflow for creating Online Taxi Booking System (OTBS) application in the Rails:
- Create basic skeleton of the application by using Rails command: rails OTBS
- Create a database in the MySQL server to store OTBS records by using SQL command in the MySQL: mysql> create database OTBS;
- Configure the application to know where the database is located and the login authority for it by modify the configuring file named database.yml that located in \ruby\library\config.
- Create Rails models (ActiveRecord), they are the objects working in controllers. By using Rails command: ruby script/generate model Taxi.
- Generate migrations that makes creating and maintaining database tables and columns easy. By using Rails command: ruby script/generate migration Taxi.
- Write controller code to make it works in the application. By Rails command: ruby script/generate controller Taxi. And then implementing different Methods
- Create Views file to present data through user interface
- Burd, B. (2007), Ruby on rails for dummies, Wily Publishing, Inc.
No comments:
Post a Comment