4/02/2009

Workshop 1-part 4

Challenge Problems:

1. Make a list of all programming languages and Web development tools used by you in prior experiences. Describe what you know about Web application frameworks before we begin.

Lists:
a.) Develop Php by using Dreamweaver MX, CSS Validator, HTML Validator andLink Checker
b.) Develop Servlet by using java studio creator and UML.

Ruby on Rails is an MVC style framework which enables rapid development of web applications using the Ruby language. The code itself is often described as 'short and elegant, yet powerful' and the concepts and features within Ruby on Rails take this elegance to a new level for web development.


2. Ruby is “an interpreted scripting language” for quick and easy object-oriented programming”. Find out about the Ruby language and discover what this means.

Find info from http://www.gsp.com/cgi-bin/man.cgi?section=1&topic=ruby

GSP.COM states that Ruby's features are as follows:

  • Interpretive (Ruby is an interpreted scripting language)
    Ruby is an interpreted language, so you don't have to recompile programs written in Ruby to execute them.
  • Variables have no type (dynamic typing) ( quick and easy object-oriented programming)
    Variables in Ruby can contain data of any type. You don’t have to worry about variable typing. Consequently, it has a weaker compile time check.
  • No declaration needed (quick and easy object-oriented programming)
    You can use variables in your Ruby programs without any declarations. Variable names denote their scope, local, global, instance, etc.
  • Simple syntax ( quick and easy object-oriented programming)
    Ruby has a simple syntax influenced slightly from Eiffel.
  • No user-level memory management (quick object-oriented programming)
    Ruby has automatic memory management. Objects no longer referenced from anywhere are automatically collected by the garbage collector built into the interpreter.
  • Everything is an object (object-oriented programming)
    Ruby is the purely object-oriented language, and was so since its creation. Even such basic data as integers are seen as objects.
  • Class, inheritance, and methods (object-oriented programming)
    Of course, as an object-oriented language, Ruby has such basic features like classes, inheritance, and methods.
  • Singleton methods (quick and easy object-oriented programming)
    Ruby has the ability to define methods for certain objects. For example, you can define a press-button action for certain widget by defining a singleton method for the button. Or, you can make up your own prototype based object system using singleton methods, if you want to.
  • Mix-in by modules (quick and easy object-oriented programming)
    Ruby intentionally does not have the multiple inheritance as it is a source of confusion. Instead, Ruby has the ability to share implementations across the inheritance tree. This is often called 'Mix-in'.
  • Iterators ( quick and easy object-oriented programming)
    Ruby has iterators for loop abstraction.
  • Closures (quick and easy object-oriented programming)
    In Ruby, you can objectify the procedure.
  • Text processing and regular expression
    Ruby has a bunch of text processing features like in Perl.
  • Bignums
    With built-in bignums, you can for example calculate factorial(400).
  • Exception handling
    As in Java(tm).
  • Direct access to the OS
    Ruby can use most Unix system calls, often used in system programming.
  • Dynamic loading (Ruby is an interpreted scripting language)
    On most Unix systems, you can load object files into the Ruby interpreter on-the-fly.

Therefore, Ruby is “an interpreted scripting language” for quick and easy object-oriented programming”.


3. What is Rails and how does it work with Ruby?

From http://hubpages.com/hub/What_is_Ruby_on_Rails, it states that

Ruby is an object-oriented scripting language which combines features of Perl and Smalltalk. The Rails framework provides a number of conventions that reduce complexity and the possibility of errors in the construction of basic client-server web applications. It uses standard libraries for client-side UI features and also for standard database structure.

4. What is meant by “convention over configuration” in regards to the use of Rails in Web application development?


Eweek.com (http://www.eweek.com/c/a/Application-Development/Ruby-on-Rails-Making-Programmers-Happy/) tells me that "Convention over configuration.,Instead of telling various parts of the technology stack five, six, seven times that you have a products table thats the data source of your product object, weve institutionalized that convention in a generalized notion: Classes are singular, tables are plural. This may sound like a trivial notion, but it has a radical impact on the amount of work that the programmer needs to do in his daily work. Were basically taking the whole world of pain that is known as configuration and making it optional. As long as you do what most people want to do most of the time, you get a free ride. No configuration necessary. So get the 80 percent by convention, tailor the last 20 percent by hand. "


5. When did Model-View-Controller begin and where is it used?

Wiki (http://en.wikipedia.org/wiki/Model-View-Controller ) tells me that MVC was first described in 1979[1] by Trygve Reenskaug, then working on Smalltalk at Xerox PARC. Model–view–controller (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other.


6. Describe the steps involved with the MVC design approach.

Wikipedia (http://en.wikipedia.org/wiki/Model-View-Controller) tells me that

MVC encompasses more of the architecture of an application than is typical for a design pattern.When considered as a design pattern, MVC is fundamentally the same as the Observer pattern. There are three step for MVC desigen.

The first step - Define Model
Is the domain-specific representation of the information on which the application operates. Domain logic adds meaning to raw data (for example, calculating whether today is the user's birthday, or the totals, taxes, and shipping charges for shopping cart items).
Many applications use a persistent storage mechanism (such as a database) to store data. MVC does not specifically mention the data access layer because it is understood to be underneath or encapsulated by the model.


The second step - Define View
Renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes.

The third step - Define Controller
Processes and responds to events (typically user actions) and may indirectly invoke changes on the model.

Workshop 1-part 3

3. To do.

3.1. Download iTunes from http://www.apple.com/itunes/download/ and subscribe to the “Leraning Rails” Podcasts from http://www.buildingwebapps.com/podcasts

Attend the Lesson 9-23 from http://www.buildingwebapps.com/podcasts

Lesson 9: The Simplest Possible Rails Application
Lesson 10: Putting the Page Contents into the Database
Lesson 11: Adding User Authentication
Lesson 12: User Management
Lesson 13: Admin Pages
Lesson 14: Using Textile Markup, plus In-Place Editing with Ajax
Lesson 15: Pages and Subpages
Lesson 16: Clean-Up
Lesson 17: Resources Page: Links, Categories, and HABTM
Lesson 18: Adding a Contact Form and Mailer
Lesson 19: Testing your site (Part 1)
Lesson 20: Testing your site (Part 2)
Lesson 21: Version control with git
Lesson 22: Deploying to a Public Web Server
Lesson 23: Performance Analysis with New Relic RPM

3.2. Study how to creating a weblog in 15 minutes with Rails 2 from the webcast at
http://media.rubyonrails.org/video/rails_blog_2.mov

3.3. Download some study guides from http://guides.rubyonrails.org/, it is very useful for referance.

3.4. Try to install the Ruby 1.8.6 (stable version), however, when running some update such "gem script/install xxx", it prompts out something are failure, and finally, i just install instantRails.

4/01/2009

Workshop 1-part 2

2.Learn about the Model View Controller (MVC) approach to Web application design

Some referance link for learning about Model view contoller are listed as follows:

1. Michael P. Peterson (2008). "International Perspectives on Maps and the Internet". Iillustrated Edition. Received 2nd April, 2009 fr0m the url - http://books.google.com.hk/books?id=Uv0CZft3nEEC&pg=PA171&dq=Model+View+Controller+approach

In this book, it tells me that the work flow of MVC, that is,

  • 1. User, manipulated one or more contollers to affect change.
  • 2. Controller, one or more controllers alter the model.
  • 3. Model, one or more views reflect the current state of the model.
  • 4. View, views are perceived by the user.
  • 5. Please see the flow figure.
  • In this book, it tells me that a model is used for storing data about a given domain, a view which renders model information in a form which a user can sense and possibly interact with; and a controller which processes and reponds to events, such as user actions or the results of a process.

2. Serge Fdida (1997). "Multimedia applications, services, and techniques: ECMAST '97". Received 2nd April, 2009 fr0m the url - http://books.google.com.hk/books?id=dJNbmJkj_jcC&pg=PA702&dq=Model+View+Controller+approach&lr=

This book tells me that MVC is an object based approach having two basic objectives, the first one that MVC can make the development of user interface componets (views) independent from the services and data (model), and form the applications (controllers), allowing different skilled groups to develop different software levels; the second one that MVC can reuse software components, both user interface software and application software. As a result of that, immediate software integration, easy unitary tests and validation, and the possibility of having multiple different user interfaces for the same application are obtained.

Workshop 1-part 1

Topic objectives - 1. Install Ruby on Rails on your computer (InstantRails or Locomotive)

1.1. Install InstantRails 2.0

1.2. Install Aptana Studio

1.3. Install MYSQL GUI Tools

1.4. Modify MYSQL root password though phpmyadmin

1.5. Create database and tables in MYSQL

  • Create database named by issuing the SQL statement - [ create database taxi_production; ]
  • Create database named by issuing the SQL statement - [ create database taxi_development; ]
  • Create database named by issuing the SQL statement - [ create database taxi_test; ]
  • Create TWO tables called passenger_origin and passenger_destination in taxi_production database with following SQL statement

=============================================

CREATE TABLE `taxi_production`.`passenger_origins`

(

`id` int(10) unsigned NOT NULL auto_increment,

`name` varchar(45) NOT NULL,

`contact` int(10) unsigned NOT NULL,

`suburb` varchar(45) NOT NULL,

`street` varchar(45) NOT NULL,

`building` varchar(45) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

=============================================

CEATE TABLE `taxi_production`.`passenger_destinations`
(
`id` int(10) unsigned NOT NULL auto_increment,

`suburb` varchar(45) NOT NULL,

`numpass` varchar(45) NOT NULL,

`taxitype` varchar(45) NOT NULL,

`time` datetime NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

===============================================

1.6. Test on Ruby on Rails
  • Create a booking system web application by Issuing command - [ rails -d mysql C:\rails_apps\bookingsys]
  • Startup the bookingsys production web appliaction, please go to bookingsys directory and issue the command [mongrel_rails start -e production]
  • Test the bookingsys web application by internet explorer with the url - [ http://localhost:3000/ ] (listening port for new web application is 3000 by default)
  • Configure Rails to point to a target database by editing database.yml file which is located at C:\rails_apps\bookingsys\config as follows

=========================

production:

adapter: mysql

encoding: utf8

database: taxi_production

username: root

password: 123456

host: localhost

=======================

1.7. Create a model for taxi online booking system in the bookingsys directory by issuing the command [ ruby script/generate model passenger_origin ] & [ ruby script/generate model passenger_destinations]

1.8. Create a controller for taxt online booking system in the bookingsys directory by issuing the command [ruby script/generate controller taxicontrol ]

1.9. Install plugin named scaffold for taxt online booking system in the bookingsys directory by issuing the command [ruby script\plugin install scaffolding ]

2.0. Install plug-in named paginate in the bookingsys by issuing the command [C:\InstantRails\rails_apps\bookingsys>ruby script/plugin install svn://errtheblog.com/svn/plugins/classic_pagination]

2.1.Edit the controller file named taxicontrol_controller.rb and input the following statement within the class of TaxicontrolController

========================================
class TaxicontrolController <>Controller
scaffold :passenger_origin
end
========================================

2.2. Reset the taxi booking system web application server.

2.3. Access the taxicontrol page by browsing the url at http://localhost:3000/taxicontrol

2.4. Click the button namely "New passenger orgin", and it will load a form, then just need fill in all fields and click create button , those field records will insert in to database (please the below figure for referance)


Figure 1.

Figure 2.

Figure 3.


2.5. Check the data whether stores in the database by using MYSQL GUI tools, please see the below figure for referance



It WORKS!!!!!!!!