Showing posts with label Workshop. Show all posts
Showing posts with label Workshop. Show all posts

Friday, May 15, 2009

Workshop 8: Ruby on Rails Workshops Report and Evaluation

Evaluation and Report

Please answer each question in this evaluation section. In your answer, please consider content/topics presented and the technologies and teaching strategies used during the Ruby on Rails Workshops. Results will be collated and used to modify the workshop series.
This form is just a format guide to you evaluation and report. Thank you for your time to complete workshop 8.

1. List what you consider to be the three strengths of Ruby on Rails workshop series


I consider the 3 strengths to be:
  1. Learn RoR from background concept to programming code, then application deployment gradually.
  2. Provide suitable materials and resources.
  3. Good in learning programming coding in Workshop 4 and 5.
2. List what you consider to be the three weaknesses of Ruby on Rails workshop series:

I consider 3 weaknesses to be:
  1. No enough time to complete the whole application.
  2. Each workshop is separated not strongly related.
  3. The work load may be too large for a part time student.
3. List what aspects of Ruby on Rails workshop series that you found to be most difficult.

The most difficult aspects were:
  1. Installation of RoR and setup of MySQL in my Mac for different versions, and too many methods.
  2. The integration use of Method, View and Control (MVC).
  3. Workshop 6: use of AJAX
  4. Need a lot of time to complete the workshops.
4. List what improvements could be made to the Ruby on Rails workshop series:

Improvements you would make include:
  1. If the course duration can be longer, it may has enough time to learn better.
  2. Improve the relation between workshops.
  3. Delivery the workshops early
Free response and reflective questions:

5. Reflect on your experiences with the other Web framework used in this subject: Was it effective? How can it be improved? Should other Web frameworks be used as well or instead of Ruby on Rails?

I only have a little experiences in Web framework (PHP and .Net). I think PHP and .Net are more suitable in business world nowadays. It may be better to learn the business software for the student easy to apply the knowlege in their working enrionment. Mircosoft provides 3 months learning edition or free Express edition in SQL server and Visual Studio for us to study.

6. Did the Developer’s or IT managers Team that you joined after workshop 4 have a preference towards using other tools to facilitate collaboration? Comment on the differences between these use of the sub-forum or Interact wiki tools from your experiences in this subject.

As I use a lot of time to complete my exercises and workshops, I can only spend a little works in the focus group of RoR workshop.

7. Further comments to add?


As the tutor in Hong Kong cannot get all the materials directly from CSU, he cannot help us much. It may be better if he can get extra materials to guide us to complete the exercises and workshops.

Workshop 7: End of the Line: production site migration and maintenance

Developers conclude their work with the OTBS and look at the options for deployment of the site. Examine the various platforms/software tools used for deployment such as UNIX environment suggested in the Discussion Notes, Mongrel or Mongrel cluster, Nginx, Subversion or Capistrano (during development stage), JRuby in the Java environment.

Which way?


The choice is up to you as this workshop present just one option and you may like to use another, such as deploying the OTBS in a .NET or J2EE environment

The OTBS is developed using Ruby on Rails (RoR). RoR is a new development language for me. I need to learn the implementation of Model-View-Controller (MOV) pattern in RoR, and code that controls or manipulates the MySQL database associated with my OTBS application. The stores business logic for validating or formatting of data that be stored in the model layer. RoR is good in it's principle of Don't Repeat Yourself (DRY). Rails attempts to impose many best practice techniques and conventions on the developer in order to create web applications that composed both elegantly and correctly (Alameda 2008).

RoR provide the modern database-driven web application, but nothing is perfect (Alameda 2008):
  • The performance of RoR is a bit slower than other web technologies.
  • Rails is a bit more demanding to deploy when compared to other solution such as PHP.
  • The rapidly changing of the Rails, makes the Rails developers to continuously improve both the framework and the development practices.
  • Not really understanding the code by the developers when they commonly use the tools (scaffolding) to generate their applications. It is a risk when something goes wrong with the application or need to modify the code to handle a special circumstance.
If I need to develop a web application for my company, I will select Microsoft ASP .Net. ASP .Net is most commonly used in business environment. It provide a easily use graphic tools for us to develop of our application. We could find a lot of resource without difficultly on the Web or other aspect such as supporting from Microsoft, books, training course and developer certificate. The business feels more confident to develop their Web site by ASP .Net, than using other open source tools such as RoR.

Can you get the OTBS Running in production mode as a minimal production server?

When deploy applications for development or testing environment, we need to (Hartl & Prochazka, 2008):
  • Configure the production database connection in the file named database.yml.
  • Create database in the production server
  • Run the migration in Rails by using of 'rake' to construt tables in it
  • Stop the development server and start a new server in production environment by using the -e flag (>ruby script/server -e production)
Minimal production server (Hartl & Prochazka, 2008):
  • Using Mongrel / Linux OS / Apache Web server, as the Rails application server
  • Setup the same softwares (such as Ruby, Rails, database and plugins) on the server like the development computer
  • Upload the Rails project to the server, follow the deploy application steps at the above to create and configure the production database
  • Install and configure the application server and webserver
A single server running a single Mongrel process is probably sufficient for most Rails application. A single server can be kept adding new Mongrels until you run out of CPU time, at that stage a new servers need to be added. Although caching can minimize database hits, the database may eventually become the application botttleneck. When that point reach, an extra database server need to be added in a master-slave setup (Hartl & Prochazka, 2008).

Reference
  1. Alameda, E. (2008), Foundation rails 2, Apress and fiends of ED books.
  2. Hartl, M. and Prochazka, A. (2008), Railsspace: building a social networking website with ruby on rails, Person Education, Inc.

Tuesday, May 5, 2009

Workshop 6: Enjoying the Ride: Web framework alternatives, scalability and flexibility

Developers may continue to build upon work with the OTBS using the topic reading to help with user registration and advanced login features from Hartl et al (2008).

o generate a controller and an action by adding a method(s) to a controller;
o create a view template for each action and to link to actions from views;
o use AJAX to improve the user experience;
Share your success by posting

progress comments and links etc to the Developers sub-forum site that has been set up for the Red team.


By following the example of the e-book "RailsSpace", I create the Home page of OTBS in my computer:


By clicking on the link: 'Register', The screen redirected to the user registration page:


The fields validation check for user registration:


Typing valid user information into the User Registration form, then submit it by clicking on 'Register!' button:


The return result of new user created successfully:


The user record in the database OTBS:


It is not easy to complete the above user registration page. I follow all the steps from charter 2 to charter 4 in the e-book 'RailsSpace', modify the contents to fit the need of the OTBS. Repeat of the debugging process by review the charters again and again.

I have learn from charter 2 to 4 in the e-book 'RailsSpace' for user registration:
  • Changing the route for home page display
  • The uses cascading style sheet (CSS)
  • Do repeat yourself (DRY) works in Ruby on Rails (ROR)?
  • The uses of migration to create and modify table
  • The uses of model validations
  • Form debug
  • Integrate uses of MOV in ROR
By following the charter 6 to 7 in the e-book "RailsSpace", I create the advanced login page of OTBS in my computer. By clicking on the link: 'Login', The screen redirected to the user login page:


Input of invalid user name and password, and select remember me option:


Input of valid user name and password, then redirect to 'Welcome' page:


The database record of the user:


The database record of the user's session:


I have learn from charter 6 to 7 in the e-book 'RailsSpace' for advanced login :
  • Test programs
  • Handle of login session
  • Protecting pages
  • Login forwarding
  • Logout & clear password
  • Use of cookie functions to remember user passward
  • More secure cookie by a secure hashing algorithm
AJAX stands for Asynchronous JavaScipt and XML. AJAX includes several technologies:
  • XHTML for the markup of Web pages
  • CSS for styling
  • Dynamic display and interaction using DOM
  • Data manipulation and interchange using XML
  • Data retrieval using XMLHttpRequest
  • JavaScript as the glue that meshes all this together
The Web page without being refreshed the contents of the entire page, when you retrieve data for a Web page by AJAX. In basic web architecture, when user clicks a link or submits a form, the form is submitted to the server. Then the server sends back a response new page to the user.
When AJAX is used, it loads an AJAX engine in the background. The engine is written in JavaScipt and its responsibility is to both communicate with the web server and display the results to the user. The server returns an HTML fragment that contains the server's response and displays only the data that is new or changed as opposed to refreshing the entire page.

Rails has a simple, consistent model to implements AJAX operations. Once the brower has render and displayed the initial web page different user actions trigger an AJAX operation:
  • Some trigger fires: by user clicking on a button or link, user making changes to the data on a form or in a field
  • The web client calls the server: A JavaScript method, XMLHttpRequest, send data associated with the trigger to an action handler on the server.
  • The server does processing: The server-side action handler does something with the data and returns an HTML fragment to the client.
  • The client receive the response: The client-side JavaScript, which Rails creates automatically, receives the HTML fragment and uses it to update a specified part of the current pages.

Wednesday, April 22, 2009

Workshop 5: Admiring the secenery Forms, AJAX screen layout and and mobile interfraces: Part C Screen layouts and forms processing:

1. Create a new application called cabs in the same projects directory to demonstrate the use of an active view.

> rails cabs
> cd cabs

Result in my computer:


2. Create a controller called Vehicle in cabs\app\controllers cabs> ruby script/generate controller Vehicle

Result in my computer:


3. Add an action to vehicle_controller.rb as the method called cabtype

class VehicleController < ApplicationController
def cabtype
end
end


Result in my computer:


4. Add a view template - cabs\app\views\vehicle\cabtype.rhtml We will edit this view in later steps but you may like to add your own test HTML code to the view at this stage.

I copy the breathe.rb from the above animal application into scenery\app\views\demo and rename the file to cabtype.rb

5. Save the view and restart the Web server and navigate to http://localhost:3000/cabs/cabtype

Result in my computer:


I change the navigate to http://localhost:3000/vehicle/cabtype, the result is OK now:


6. Create a file in the public directory - \cabs\public called input.html

I had created a file in the public folder (\cabs\public) called input.html

7. Edit the vehicle_controller.rb here is a start. The data in each form element in the Rails application can be accessed via its name and a hash called params

class VehicleController < ApplicationController
def cabtype
@data1 = params[:text1]
@data2 = params[:check1]
@data3 = params[:radios1]
@data4 = params[:building1]
end
end


The vehicle_controller.rb in my computer:


8. Edit the view template cabtype.rhtml

The cabtype.rhtml in my computer:


9. Start the Web server and go to the opening page of this application at http://localhost:3000/input.html

Result in my computer:


10. Submit the forms data. What do you find?

When I submit the forms with the data that provided, the current Web page are redirected from input.html to vehicle (call the vehicle controller to display the user input). But an error page return. The error occur in the action controller for invalid authenticity token. In the error page, list out the parameter that I had input.

Result in my computer:

Workshop 5: Admiring the secenery Forms, AJAX screen layout and and mobile interfraces: Part B The active view:

1. Create a new application called scenery in the same projects directory to demonstrate the use of an active view.

> rails scenery
> cd scenery


Result in my computer:


2. Create a controller called Demo in scenery\app\controllers scenery> ruby script/generate controller Demo

Result in my computer:


3. Add an action to demo_controller.rb as the method called rubycode

class DemoController < ApplicationController
def rubycode
end
end


The method called rubycode is added into demo_controller.rb:


4. Add a view template - scenery\app\views\demo\rubycode.rhtml We will edit this view in later steps but you may like to add your own test HTML code to the view at this stage.

I copy the breathe.rb from the above animal application into scenery\app\views\demo and rename the file to rubycode.rb

5. Save and restart the Web server and navigate to http://localhost:3000/scenery/rubycode

Result in my computer:


I change the navigate to http://localhost:3000/demo/rubycode, the result is OK now:


6. Use the Time.now example to pass data from an action to a view.

I change rubycode.rb in the scenery\app\views\demo:


Result in the Web browser:


7. Modify and save the rubycode action with a value for the time instance variable in the DemoController class in app\controllers\demo_controller.rb

class DemoController < ApplicationController

def rubycode

@time_now = Time.now
end
end


The demo_controller.rb in my computer:


8. Then modify and save the corresponding view template in \app\views\demo\rubycode.rhtml by adding a call by reference to the action’s instance variable: The time is <%= @time.now %>

The rubycode.rhtml in my computer:
AS the error occur, I change the statement into:
The time is <%= @time_now %>


9. Restart the Web server and navigate the browser to http://localhost:3000/demo/rubycode

The instance variable time_now are passing successfully from the Ruby class to the view templates by reference. Result in my computer:

Saturday, April 18, 2009

Workshop 5: Admiring the secenery Forms, AJAX screen layout and and mobile interfraces: Part A Viewing the action:

1. Create the Rails application framework in the projects folder: C:\InstantRails\...\projects\>rails animals

I create the application framework into the folder named Sites in my Mac:


2. Running the application on localhost:3000 using the WeBrick ruby server (or Mongrel as alternative) and access via Web browser at http://localhost:3000/

I go into the folder that created in the above, then run the command "ruby script/server" to start the Web server.


The Web browser at http://locathost:3000/


3. Create the controller to make the application do an action. This is under the controller-action/model-view structure.

Stop the WEBrick server each time you edit Ruby classes and then re-start or refresh the views you are testing. Use the Ruby command below:

>ruby script/generate controller Mammal

Result in my computer:


The mammal_controller.rb contains just a bare class description:
class MammalController < ApplicationController
end


Result in my computer:


and the ApplicationController class inherits from ActionController::Base class in the ActionController module under Rails.

Result in my computer:



4. Test the controller by starting the WEBrick server and navaigatibng the browser to http://localhost:3000/mammal Note how the controller name is appended to the end of the URL and that no action resulted because there are no controller methods.


Result in my computer:


5. Create an action by editing and saving the mammal_controller.rb class in projects\animals\app\controllers using your text editor to add the method below:

class MammalController < ApplicationController
def breathe
end
end


The mammal_controller.rb in my computer:


6. Start the WEBrick server and browse at http://localhost:3000/mammals/breathe where you will get a “missing template” message since it is missing a view for the breathe method. Rails is trying to connect the breathe method action of the mammal controller to a view, by using the action’s name – breathe. This view template is created as breathe.rhtml and stored in the \projects\animals\views\mammal directory.

Result in my computer:


7. Create and save a view in that directory by using a text editor to create a view called breathe.rhtml

Result in my computer:


8. Try Ruby code and HTML in the action view by using the <%....%> wrapper around the inserted Ruby code. Here are some snippets to try from workshop 4:

I modify the breathe.rhtml:


Result in my computer:

Workshop 5: Developer Role (Red team)

Although the role of IT infrastructure manager may be more challenging, I select the role of developer in my workshops. As I am more like to learn the Ruby on Rails programming.

Monday, March 30, 2009

Workshop 4: Riding the Rails with Ruby

To do:
1. Spend some time moving your way through the 46 Ruby coding examples in the Ruby Tutorial with Code from http://www.fincher.org/tips/Languages/Ruby/

I have go through the 46 Ruby coding examples:
  1. Install Ruby
  2. Our first program
  3. Output in Ruby
  4. Reading from the Console
  5. Functions
  6. Open Classes
  7. Variable naming
  8. Interesting tidbits about Ruby
  9. Variable Types
  10. Missing
  11. Quotes
  12. Objects
  13. Big Numbers
  14. Parallel Assignment
  15. Collections (Arrays, Hashes, Ranges)
  16. Control Statements (if, case, for, exit, loop)
  17. Statement modifiers (if, unless, while)
  18. Iterators (while, times, each, each with ranges, upto)
  19. You gotta have class (classes, ToString, to_s, subclassing, virtual attributes)
  20. Regular Expressions
  21. Blocks
  22. File I/O
  23. method_missing - a wonderful idea
  24. "BEGIN" / "END"
  25. converting between strings and ints
  26. Using XML Dom Parser
  27. Run a few lines directly from the command line with the "-e" option
  28. Editing files in place
  29. Example of printing duplicate lines in sorted file
  30. Ruby has it own interpreted shell, irb
  31. Ruby can take input stdin
  32. to pass a string on the uri it needs to "escape" first
  33. Example to remove "funny" characters from a filename
  34. Looping over list of arguments
  35. Miscellaneous Commands
  36. DataTime
  37. Using 'requie'
  38. BuiltIn Command Interpreter
  39. Introspection with ObjectSpace
  40. Testing
  41. Read a URL and print the web page to the screen
  42. Example of drawing a line on a canvas in Tk
  43. irb - interactive ruby
  44. RubyGems a ruby package installer
  45. Ruby on Rails
  46. Ruby Quotes
2. What are the syntax differences in the way that Ruby and Javascript use the if statement?

Ruby if statement:


Javascript if statement:


The syntax differences in Ruby and Javascript use the if statement:
  1. Both Ruby and Javascript If statement start with " if "
  2. Both of them write the actual condition just after the word " if ", but Javascript write the actual condition in between the open " ( " and closed " ) " brackets
  3. In Ruby specifies what will happen if the condition is satisfied, is written before word " end ", but in Javascript it is written between open " { " and closed " } " curly brackets (or braces)
  4. In Ruby uses the " else " or " elseif ", but in Javascript uses " else " or " else if " to specify what to do next if the condition is not satisfied.
3. While Ruby and Python are quite similar, can you find some similarities between Ruby and Javascript?

Ruby has many of the same language features that JavaScript has, including (Seidman, 2006):
  • extension by mixin (mixin in OO programming, is a class that provides a certin functionality to by inherited by a subclass)
  • duck typing (duck typing is a style of dynamic typing in which an object's current set of methods and properties determines the vaild semantics, rather than its inheritance from a particular class or implementation of a spceific interface.)
  • a YAML equivalent JavaScript Object Notation (YAML is a human-readable data serialization format that takes concepts from language sech as XML, C, Python, Perl)
  • arbitrary class and object extension (ie. adding methods/properties to classes or specific objects at any time)
  • simple arrays and hashes
  • has first-class functions, which are the same (though not identical) as blocks.

Challenge Problems:
1. Create, test and debug a Ruby program called dognames.rb or catnames.rb to accept 3 names from the keyboard and to display each name on the screen in alphabetical order WITHOUT using a data structure such as a list.

The dognames.rb program:


The testing of the dognames.rb program:


2. Write a Ruby program called fizzbuzz.rb that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

The fizzbuzz.rb program:


The result of the fizzbuzz.rb program:


3. Compare the Ruby and Python versions of the dog years calculator:


Reference
  1. Seidman, G. (2006), Faq and javascript vs. ruby (was re: rubynuby - client side ruby?), newgroups.derkeller.com, Retrieved from http://newsgroups.derkeiler.com/Archive/Comp/comp.lang.ruby/2006-02/msg02949.html on 1st April, 2009

Thursday, March 26, 2009

Workshop 3: Online Taxi Booking System: MySQL and Database design:

To do:
1. Set up the MySQL tools on your computer as described in section 6 above.

I had install the 'Sequel Pro' in my Mac, use it to connect the MySQL database named test, browse the table employees in it:


2. Rails will setup a new application directory for each of your Web application projects. Get InstantRails (Windows) or Locomotive (MacOS) running on your machine. Both packages install Ruby, Rails, a Web server or one called ‘Mongrel’ or another small Ruby Web server called ‘WEBrick’, and MySQL “inside a bubble” as I call it so that others parts of your system are not modified (Similarly ZOPE does with installing its own Web server and Python versions)

Run the Locomotive and Create Rails Application named OTBS:


3. Once Rails is running you at http://localhost:3000, you need to configure database access. Connection to the database is specified in the config/database.yml file.

Running Rails in my Mac:


The database.yml that under the config folder:


4. Generate the Passenger model by creating the MySQL database and ‘passengers’ table from the information above.

Create the table passengers in database OTBS by MySQL tools Sequel Pro:


Generate the Passenger model in the Terminal: ruby script/generate model Passenger


The model Ruby class located in app/models/passenger.rb:


5. Further work on understanding MySQL under Rails by David Mertz:
a. See “Fast-track your Web apps with Ruby on Rails” at http://www-128.ibm.com/developerworks/linux/library/l-rubyrails/

Summary after reading of the “Fast-track your Web apps with Ruby on Rails”:
  • Introducing Rails - Rails provides a very clear and focused MVC way of thinking
  • Describe how to building a simple application
  • Describe how to creating customizable content
  • Describe how to changing the model
  • Rails gives us a extremely quick way to develop flexible Web applications.
  • Rails development offers us a clear path from a half-formed idea to a fully functioning Web applciation.
b. The “Rolling with Ruby on Rails” series and “Cookbook recipes by Curt Hibbs and others beginning at http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html

Summary after reading of the “Rolling with Ruby on Rails” series and “Cookbook recipes by Curt Hibbs":
  • The article steps through using Rails to develop a Web application
  • What are Ruby and Rails?
  • Installation steps of Ruby on Rails (install: Ruby, Rails, MySQL, MySQL-Front)
Web application development steps using Rails:
  1. Create an empty Rails Web application (eg. Run the command: rails cookbook)
  2. Test the empty Web application (eg. Run the command: ruby script\server)
  3. Introduction of Rails application's directory structure
  4. Create Controller class (eg. Run the command: ruby script\generate controller Mytest)
  5. How to use the index method of MytestController to display 'Hello World' ?
  6. How to create database and table in MySQL using MySQL-Font
  7. Create Model (eg. Run the command: ruby script\generate model Recipe)
  8. How to create, list and delete database record by using the Controller and add the command scaffold?
  9. How to create actions and Views?
  10. How to assign relationship between tables and make them work in the Rials?