Friday, April 24, 2009

Week 11: Rails Passion Course

  1. Week 11: Action Controller Basics (Action Controllers are the core of a web request in Rails. They are made up of one or more actions that are executed on request and then either render a template or redirect to another action. An action is defined as a public method on the controller, which will automatically be made accessible to the web-server through Rails Routes.
    Topics to be covered: What is ActionController?, ActionController classes, Request handling, Parameters, Session & Flash, Rendering, Redirection, Classic problem of user refresh & redirection, Routing (request mapping))
  2. 5526_rails_controller.zip (Unzip it in a directory of your choice and read lab document from /rails_controller/index.html to proceed) (4/24/09: Downloaded)
  3. Week 11 Resources
    o Basics
    + Action Pack from api.rubyonrails.org
    + ActionController::Base API from api.rubyonrails.org
    + ActionController::Flash API from api.rubyonrails.org
    o Routing
    + ActionController::Routing API from api.rubyonrails.org
    o Caching
    + ActionController::Caching API from api.rubyonrails.org
  4. Presentation - PDF: 1 slide per page (OR) OpenOffice file (47 pages) (4/27/2009: Done)
  5. Online Lab document/Change Log (This is the same document you will find in the hands-on lab zip file) (93 pages)
  6. EXERCISE 0: Start MySQL database server. (p.2)
  7. EXERCISE 1: Requests and Parameters I (p.2-15)
  8. (1.0) Open and run "helloworld" sample application (p.2-4)
  9. (1.1) Observe parameters in development log. (p.4-6)
  10. (1.2) Modify the controller (p.6-9)
  11. (1.3) Pass the parameters through URL (p.9-11)
  12. (1.4) Observe the parameters in development log (p.11-12)
  13. (1.5) Observe the controller and action parameters (p.12-16) PROBLEM: :action not displayed. The fix was to rename ":action_name" to ":action1_name"
  14. EXERCISE 2: Request and Parameters II (p.16-34)
  15. (2.0) Open and run "helloname" sample application project. (p.16-19)
  16. (2.1)Observe parameters in development log. (p.19-22)
  17. (2.2) Study how user input data is collected as parameters (p.22-25)
  18. (2.3) Study how parameters are accessed in the controller (p.25-26)
  19. (2.4) Add another column to the table through migration (p.26-30)
  20. (2.5) Modify the code of index.html.erb and respond.html.erb files. (p.30-31)
  21. (2.6) Run the helloname application. (p.31-33)
  22. (2.7) Observe the parameters in development log. (p.33-34)
  23. EXERCISE 3: Session and Flash (p.34-63)
  24. (3.1) Use session. (p.34-40)
  25. (3.2) Use ActiveRecordStore to maintain session data (p.40-56)
  26. (3.3) Use Flash (p.56-63)
  27. EXERCISE 4: Rendering (p.63-72)
  28. (4.1) Use render :text (p.64-66)
  29. (4.2) Use render :action => :respond (p.66-68)
  30. (4.3) Use render :action => 'respond" (p.68-70)
  31. (4.4) Use render :template (p.70-72)
  32. EXERCISE #5: User refresh problem with "render" - Use "redirect_to" (p.72-87)
  33. (5.1) Observe the problem of using render :action=>'list' when a user press "Refresh" (p.73-80)
  34. (5.2) Correct the problem by using redirect :action=>'list' instead (p.80-87)
  35. EXERCISE #6: Routing Basics (p.87-
  36. (6.1) Use Rails Console (for routing experimentation) (p.87-88)
  37. (6.2) Named routes (p.88-92)
  38. Homework


Tuesday, April 21, 2009

Week 10: Rails Passion Course

  1. Week 10: ActiveRecord Associations Basics (Topics covered: What is an Association?, Auto-generated methods, Cardinality, Unsaved objects and association)
  2. Week 10 Resources
    o ActiveRecord::Associations:ClassMethods API from api.rubyonrails.org
    o Building Relationships Between Rails Models tutorial by Brian Leonard and Gail Chappell
  3. 5525_rails_associations.zip (Unzip it in a directory of your choice and read lab document from /rails_associations/index.html to proceed) (4/21/09: Downloaded)
  4. Presentation - PDF: 1 slide per page (OR) OpenOffice file (22 pages)
  5. Online Lab/Change Log document (This is the same document you will find in the hands-on lab zip file) (84 pages)
  6. EXERCISE #0: Start MySQL database server (p.g2) (4/21/2009: done)
  7. EXERCISE #1: Add one-to-many association to rubyweblog application. (p.2-28)
  8. (1.1) Create Comment Model class (p.3-6)
  9. (1.2) Migrate database (p.6-7)
  10. (1.3) Add association macros to the Model classes (p.8-11)
  11. (1.4) Modify controller (p.11-15)
  12. (1.5) Modify [view] templates (p.15-17)
  13. (1.6) Save the changes (p.17-18)
  14. (1.7) Refresh the browswer and perform user operation (p.19-21)
  15. (1.8) Observing the database tables (p.22-26)
  16. (1.9) Use Rails Console (p.26-28)
  17. EXERCISE #2: Options for has_many (p.28-46)
  18. (2.0) Create fresh test data using migration (p.28-33)
  19. (2.1) Exercise :order option (p.34-39)
  20. (2.2) Exercise :destroy option (p.39-46)
  21. EXERCISE #3: Add many-to-many association to rubyweblog application (p.46-65)
  22. (3.1) Create Category model class (p.46-49)
  23. (3.2) Create "categories_posts" table through migration (p.49-55)
  24. (3.3) Add many-to-many relationship between Post and Category models (p.55-58)
  25. (3.4) Create test data through migration (p.59-64)
  26. (3.5) Use Rails Console (p.64-65)
  27. EXERCISE #4: Add many-to-many association to rubyweblog application using through - not ready yet
  28. (4.1) Recreate rubyweblog_development database (p.66-68)
  29. (4.2) Remove migration files that are not needed (p.68-69)
  30. (4.3) Create a join model (p.70-73)
  31. (4.4) Modify Post and Category models (p.73-75)
  32. (4.5) Create test data through migration (p.75-79)
  33. (4.6) Verify that the data tables are created correctly (p.79-83)
  34. (4.7) Use Rails Console (p.83-84)
  35. Finished Exercises (4:30pm)
  36. Homework (p.84)

Sunday, April 19, 2009

Week 9: Rails Passion Course

  1. Week 9: ActiveRecord Basics (Topics covered: What is Active Record?, Active Record Object Creation, Find operation, Dynamic Attribute-based Finders, Validation, Migration, Callbacks, Exception Handling)
  2. Week 9 Resources
    1. Basics
      1. ActiveRecord from api.rubyonrails.org
      2. ActiveRecord::Base API from api.rubyonrails.org
      3. ActiveRecord tutorial screencast by Gregg (July 2007)
      4. Advanced ActiveRecord presentation by Obie Fernandez
    2. Validation
      1. ActiveRecord::Validations::ClassMethods API document from rubyonrails.com
      2. Various examples from railsbrains.com
    3. Migration
      1. ActiveRecord::Migration API document from railsbrains.com
      1. Generate a migration from an existing MySQL database posting in ruby-forum.com
  3. 5522_rails_activerecord.zip (Unzip it in a directory of your choice and read lab document from /jrubyrails_basics/index.html to proceed) (4/19/09: Downloaded)
  4. Presentation --PDF: 1 slide per page (OR) OpenOffice file (44 pages) (4/21/09: Read)
  5. Online Lab/Change Log document (This is the same document you will find in the hands-on lab zip file) (105 pages)
  6. EXERCISE #0: Start MySQL database server. (p.2)
  7. EXERCISE #1: Creation of ActiveRecord Objects (p.2-39)
  8. (1.1) Create a new NetBeans project (with JRuby 1.1.4 and WEBrick) (p.3-6)
  9. (1.2) Create database (p.6-7)
  10. (1.3) Generate Model (3 attributes) (p.8-10)
  11. (1.4) Create database table through migration (p.10-19)
  12. (1.5) Create ActiveRecord objects through Rails Console (p.20-28)
  13. (1.6) Create database table rows through migration (p.29-39)
  14. EXERCISE #2: ActiveRecord#find (p.40-44)
  15. (2.1) find(:all) with various options (p.40-42)
  16. (2.1.1) With limit, offset, select options (p.40)
  17. (2.1.2) With order parameter (p.40-41)
  18. (2.1.3) With conditions parameter (p.41-42)
  19. (2.2) find(:first) (p.42)
  20. (2.3) find() with id (p.42)
  21. (2.4) Dynamic attribute-based finders (p.42-43)
  22. (2.5) find_by_sql method (p.43)
  23. (2.6) find_or_create_by_ method (p.43-44)
  24. (2.7) find() with params (44) -- EMPTY/SKIPPED
  25. EXERCISE #3: Validation (p.44-75)
  26. (3.1) Delete all rows of the "users" table through migration (p.44-49)
  27. (3.2) Perform validation using validation helpers (p.50-60)
  28. (3.3) Add email field to the users table (p.61-69)
  29. (3.4) Add validation logic for the "email" field (p.70-71)
  30. (3.5) Perform validation testing on the email field (p.72-75)
  31. EXERCISE #4: Migrations (p.76-105)
  32. (4.1) Add a new column (p.76)
  33. (4.2) Rename a column - chane "email" to "email_addr" (p.76-83)
  34. (4.3) Roll back the change - change "email_addr" to "email" (p.84-89)
  35. (4.4) Display "schema.rb" file that maintains the current migration number (p.90-91)
  36. (4.5) Exercise with multiple veresions of migration files (p.92-105)
  37. EXERCISE #5: Statistics (p.106-107)
  38. EXERCISE #6: Callbacks (p.108--114)
  39. (6.1) Add callback to the Model (p.108-114)
  40. FINISHED EXERCISES (11:38am on 4/21/2009)
  41. Homework (p.115)
  42. HW-part 1: Migration: Add another column called "credit_card" to the users table as following as part of ActiveRecord_Creation project. (Or you can create a new project and new database. I will call the new project as MyActiveRecord here.) The type of credit_card field is string. (4/21/09: done, HINT ON PAGE 76) OUTPUT: (in C:/cygwin/home/jasnow/RAILSPASSION/ActiveRecord_Creation)
    == 20090421151649 RenameEmailField: migrating =================================
    -- rename_column(:users, :email, :email_addr)
    -> 0.2011s
    == 20090421151649 RenameEmailField: migrated (0.2018s) ========================
    == 20090421162301 AddCreditCxard: migrating ===================================
    -- add_column(:users, :credit_card, :string)
    -> 0.1927s
    == 20090421162301 AddCreditCxard: migrated (0.1933s) ==========================
  43. HW9-part 2: Validation: Add the following validation logic for the credit_card field.
    1. It has to be unique.
    2. User can enter the credit card format in the following format. The x has to be numeric value.
      1. xxxx-xxxx-xxxx-xxxx (format #1)
      2. xxxx xxxx xxxx xxxx (format #2)
      3. xxxxxxxxxxxxxxxx (format #3) NOTE: 16 digits
  44. HW9-part3: Callbacks: Use callbacks - before_save and before_create - to convert the format #1 and format #2 to format #3 meaning the actual table contains only format #3. (4/21/09: done, HINT ON PAGE 108) Loading development environment (Rails 2.1.0)
    RAILS CONSOLE: JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    >> ?> user = User.new(:name => "OnlyDigits", :hobby => "tennis", :age => 49, :email_addr => "jasnow@hotmail.com", :credit_card => "1234567890123456" )
    => #
    >> user.save
    => true
    >> user = User.new(:name => "Digits N. Blanks", :hobby => "swimming", :age => 19, :email_addr => "dnbxxx@gmail.com", :credit_card => "1234 5678 9012 3456" )
    => #
    >> user.save
    => true
    >>
    User.create(:name => "Digits N. Dashes", :hobby => "swimming", :age => 19, :email_addr => "dndxxx@gmail.com", :credit_card => "1234-5678-9012-3456" )
    ?> => #
    >> User.create(:id => 20, :name => "Bad DashInColumn1", :hobby => "swimming", :age => 19, :email_addr => "bdc1xxx@gmail.com", :credit_card => "-1234567890123456" )
    => #
    >> user = User.new(:name => "Bad DashInColumn1", :hobby => "swimming", :age => 19, :email_addr => "bdc1xxx@gmail.com", :credit_card => "-1234567890123456" )
    => #
    >> user.save
    => false
    >>
    ?> user = User.new(:name => "BadDashInColumn1", :hobby => "swimming", :age => 19, :email_addr => "bdc1xxx@gmail.com", :credit_card => "-1234567890123456" )

    => #
    >> ?> user.save
    => false
    >> user = User.new(:name => "BadValue", :hobby => "swimming", :age => 19, :email_addr => "bdc1xxx@gmail.com", :credit_card => "BAD VALUE" )
    => #
    >> user.save
    => false
  45. HW9-part4: Submit: Send the following files to railshomeworks@sun.com with Subject as RailsHomework-rails_activerecord.
  • Zip file of the the MyActiveRecord NetBeans project. (Someone else should be able to open and run it as a NetBeans project.) You can use your favorite zip utility or you can use "jar" utility that comes with JDK as following.
    • cd MyActiveRecord directory> (assuming you named your project as MyActiveRecord)
    • jar cvf MyActiveRecord.zip MyActiveRecord (MyActiveRecord should contain nbproject directory)
  • Captured output screen - name it as RailsHomework-rails_activerecord.gif orRailsHomework-rails_activerecord.jpg (or RailsHomework-rails_activerecord.)
    • Any screen capture that shows that your program is working is good enough.
  • Emailed on 4/21/2009/DONE with your lesson.

Week 8: Rails Passion Course

  1. Week 8: Ruby/JRuby and Rails Support in NetBeans (Topics covered: Coding/Editing, Refactoring, Testing, Debugging, Profiling, Deployment)
  2. 5553_rails_netbeans.zip (Unzip it in a directory of your choice and read lab document from /rails_netbeans/index.html to proceed) (4/19/09: Downloaded)
  3. Week 8 Resources
    o Websites
    + NetBeans Ruby and Rails Learning Trail
    + NetBeans Ruby wiki
    o Database
    + Ruby Database Integration with NetBeans 6.1 from wiki.netbeans.org
    + Using MySQL Administrator Tool of NetBeans 6.1 Beta blog
    o Rails support in NetBeans blogs
    + Surprising Contender: NetBeans as a Ruby+MYSQL IDE blog by Timothy M. O'Brien (April 2008)
    + So long TextMate?... Hello NetBeans? Really? Yeah, really. blog (April 2008)
    + Tor Norbye's Weblogs
    + Why You Want NetBeans (for Rails development) blog by Eric Armstong (May, 2008)
    # See the end part of the blog.
  4. Presentation - PDF: 1 slide per page (OR) OpenOffice file (36 pages) (4/19/09: Read)
  5. Online Lab/ChangeLog document (This is the same document you will find in the hands-on lab zip file) (2 pages)
  6. EXERCISE 1 (60 minute screencast): In this exercise, you are going to watch and listen variious NetBeans screencasts from the NetBeans Ruby and Rails Learning Trail website and try them yourselves.
  7. (1.1) Using Code Completion (2:04 minutes)
  8. (1.2) Using Hints and Quick Fixes (3:21 minutes)
  9. (1.3) Using Live Code Templates (2:29 minutes) (http://ruby.netbeans.org/codetemplates-ruby.html)
  10. (1.4) Editing Ruby Code (4:55 minutes)
  11. (1.5) Debugging Ruby Code (4:38 minutes)
  12. EXERCISE 2 (30 minute screencast): In this exercise, you are going to exercise various Ruby editing features of NetBeans.
  13. (2.1) Ruby Editing features (4/19/09: Printed out and read this section - 14 pages)
  14. Homework (No Homework)

Thursday, April 16, 2009

Week 7: Rails Passion Course

  1. Week 7: Scaffolding (Scaffolding is a way to quickly put an Active Record class online by providing a series of standardized actions for listing, showing, creating, updating, and destroying objects of the class. These standardized actions come with both controller logic and default templates that through introspection already know which fields to display and which input types to use. // Topics covered: What is scaffolding?, Controller (that is generated through scaffolding), Templates (that are generated through scaffolding))
  2. 5523_rails_scaffold.zip (Unzip it in a directory of your choice and read lab document from /rails_scaffold/index.html to proceed) (4/16/09: Loaded)
  3. Week 7 Resources
    o Web services, Rails-style blog by Jamis (March, 2006)
    + Explains how respond_to works - respond_to will be covered in REST topic below
    o Rails 2.0 Scaffolding blog by David Lynch
  4. Week 7 Presentation - PDF: 1 slide per page (OR) OpenOffice file (15 pages) (4/16/09: Read)
  5. Week 7 Exercises -Online Lab/Change Log document (This is the same document you will find in the hands-on lab zip file) (72 pages) (4/17/09: Read thru the powerpoints)
  6. #0: Start Db (done) (p.2)
  7. (1.1) Create new project: rubyweblog with WEBrick and JRuby 1.1.4. (p.3-4)
  8. (1.2) Create new database (p.4-5)
  9. (1.3) Generate scaffold (p.6-18)
  10. (1.4) Migrate the database (to Current Version) (p.19-21)
  11. (1.5) Add a URL routing and delete index.html from Public directory (p.22-25)
  12. (1.6) Build and run the application (p.26-27)
  13. (1.7) Study control flow - Displaying the 1st page (p.28-31)
  14. (1.8) Study control flow - Creating a new post (p.31-37)
  15. EXERCISE #2: Add another field to the model in rubyweblog application
  16. (2.1) Add another field to the model (through migration) (p.37-41)
  17. (2.2) Modify [view] templates (p.42-44)
  18. (2.3) Save changes and Refresh the browser (p.45-53)
  19. (2.4) Add a validation (p.54-59)
  20. (2.5) Change the look and feel (p.60-62)
  21. (2.6) Perform various find operations through Rails console (p.63-67)
  22. NOW FOR THE HOMEWORK
  23. Week 7 Homework (68 pages) (p.67-68)
  24. HW7: Step 1: Start DB. (p.2)
  25. HW7: Step 2: Create new project (myscaffoldingapp) with WEBrick and JRuby 1.1.4. (p.2-3)
  26. HW7: Step 3: Now create databases. (p.3-4)
  27. HW7: Step 4: Now create scaffold - Course model with 2 attributes (name:string and credit:integer) (p.6-10)
  28. HW7: Step 5: Now migrate the database. (p.11-21)
  29. HW7: Step 6: Fix Configuration (routes.rb == "courses", deleted index.html) (p.22-25)
  30. HW7: Step 7: Build/Ran (p.26-27) http://localhost:3000/courses/new (WORKED; Added 7 courses/credits)

Week 6: Rails Passion Course - On My New Mac

  1. Repeated Week 6 Homework (HW6) on my new White Mac Laptop.
  2. (AL#1) Creating new project: studentapp in /Users/whitemac/NetBeansProjects directory using "Built-in JRuby 1.1.4" and "Glassfish V3".
  3. Note the Mac experience is different from PC. Asked for Database Configurations/Accepted defaults/Continued.
  4. Then went to "Install Rails" and I selected "Update JRuby OpenSSL Support" and it worked. Then I selected "Update Rails" (from 2.1.0) to 2.3.2.
  5. Then I SKIPPED "Install Warbler" for now.
  6. Selected "Finished" and it failed and asked for run "sudo gem update --system" so I did. After the "gem update" finished, I selected "OK" and it finished creating the Rails Project.
  7. NOTE: Appears that MySQL is not installed on MAC, so going back to AL#0 to install MySQL on the MAC.
  8. THURSDAY (Next Day): Found another article (http://sheldonconaty.com/?p=7) and followed it to use this article: http://www.hennessynet.com/blog/?p=40 about setting up .bash_profile and macports and mySQL.
  9. Here is the log: $ sudo port install mysql5 +server (p.1)
    ---> Fetching zlib
    ---> Attempting to fetch zlib-1.2.3.tar.bz2 from http://www.zlib.net/
    ---> Verifying checksum(s) for zlib
    ---> Extracting zlib
    ---> Applying patches to zlib
    ---> Configuring zlib
    ---> Building zlib
    ---> Staging zlib into destroot
    ---> Installing zlib @1.2.3_2
    ---> Activating zlib @1.2.3_2
    ---> Cleaning zlib
    ---> Fetching openssl
    ---> Attempting to fetch openssl-0.9.8k.tar.gz from http://distfiles.macports.org/openssl
    ---> Verifying checksum(s) for openssl
    ---> Extracting openssl
    ---> Applying patches to openssl
    ---> Configuring openssl
    ---> Building openssl
    ---> Staging openssl into destroot
    ---> Installing openssl @0.9.8k_0
    ---> Activating openssl @0.9.8k_0
    ---> Cleaning openssl
    ---> Fetching ncursesw
    ---> Attempting to fetch ncurses-5.7.tar.gz from http://mirrors.ibiblio.org/pub/mirrors/gnu/ftp/gnu/ncurses
    ---> Verifying checksum(s) for ncursesw
    ---> Extracting ncursesw
    ---> Configuring ncursesw
    ---> Building ncursesw
    ---> Staging ncursesw into destroot
    ---> Installing ncursesw @5.7_0
    ---> Activating ncursesw @5.7_0
    ---> Cleaning ncursesw
    ---> Fetching ncurses
    ---> Verifying checksum(s) for ncurses
    ---> Extracting ncurses
    ---> Configuring ncurses
    ---> Building ncurses
    ---> Staging ncurses into destroot
    ---> Installing ncurses @5.7_0
    ---> Activating ncurses @5.7_0
    ---> Cleaning ncurses
    ---> Fetching readline
    ---> Attempting to fetch readline-6.0.tar.gz from http://distfiles.macports.org/readline
    ---> Verifying checksum(s) for readline
    ---> Extracting readline
    ---> Applying patches to readline
    ---> Configuring readline
    ---> Building readline
    ---> Staging readline into destroot
    ---> Installing readline @6.0.000_1
    ---> Activating readline @6.0.000_1
    ---> Cleaning readline
    ---> Fetching mysql5
    ---> Attempting to fetch mysql-5.0.77.tar.gz from http://mysql.orst.edu/Downloads/MySQL-5.0
    ---> Attempting to fetch mysql-5.0.77.tar.gz from http://mysql.mirrors.pair.com/Downloads/MySQL-5.0/
    ---> Verifying checksum(s) for mysql5
    ---> Extracting mysql5
    ---> Applying patches to mysql5
    ---> Configuring mysql5
    ---> Building mysql5
    ---> Staging mysql5 into destroot
    ---> Creating launchd control script
    ###########################################################
    # A startup item has been generated that will aid in
    # starting mysql5 with launchd. It is disabled
    # by default. Execute the following command to start it,
    # and to cause it to launch at startup:
    #
    # sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
    ###########################################################
    ---> Installing mysql5 @5.0.77_2+server
    ******************************************************
    * In order to setup the database, you might want to run
    * sudo -u mysql mysql_install_db5
    * if this is a new install
    ******************************************************
    ---> Activating mysql5 @5.0.77_2+server
    ---> Cleaning mysql5
    al-snows-macbook:~ whitemac$
    al-snows-macbook:~ whitemac$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
    Password:
  10. Then did this:
    $ sudo -u mysql mysql_install_db5
    Password:
    Installing MySQL system tables...
    090416 20:07:40 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
    090416 20:07:40 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
    090416 20:07:40 [Warning] Setting lower_case_table_names=2 because file system for /opt/local/var/db/mysql5/ is case insensitive
    OK
    Filling help tables...
    090416 20:07:40 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
    090416 20:07:40 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
    090416 20:07:40 [Warning] Setting lower_case_table_names=2 because file system for /opt/local/var/db/mysql5/ is case insensitive
    OK
    To start mysqld at boot time you have to copy
    support-files/mysql.server to the right place for your system
    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
    To do so, start the server, then issue the following commands:
    /opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
    /opt/local/lib/mysql5/bin/mysqladmin -u root -h al-snows-macbook.local password 'new-password'


Friday, April 10, 2009

Week 6: Rails Passion Course

  1. Week 6: Rails Basics (Topics covered: What is and Why Ruby on Rails?, Building HelloWorld Rails application step by step, Key concepts of Rails application development - App directory structure (MVC), Environment, Rake, Generator, Migration, Rails console)
  2. Week 6 Resources
    o Web sites
    + Ruby and Rails Learning Trail website from netbeans.org
    # Pretty comprehensive set of Rails tutorials
    + Ruby on Rails API reference from api.rubyonrails.org
    o Ruby on Rails tutorials
    + Ruby on Rails 2.1.x Tutorial site
    # Pretty comprehensive set of Rails tutorials
    + railscasts.com
    + Creating a Ruby Weblog in 10 minutes tutorial from netbeans.org
    + Getting Started with JRuby on GlassFish Screencast from glassfish.dev.java.net
    + JRuby on Rails for the enterprise (with performance) article
    + What is Ruby on Rails tutorial from onlamp.com
    + Sample Catalog Application using JRuby and Rails tutorial (Oct. 2007) by Carol McDonald
    o MySQL
    + Connecting to a MySQL Database tutorial from netbeans.org
    o Articles
    + NetBeans Ruby Pack article from netbeans.org
    o Presentations
    + Rails Presentations from ruby-doc.org
    + Ruby on Rails presentation presentation by Miguel Vega and Ezwan Faiz
    + Pursuing beauty with Ruby on Rails presentation by David Heinemeier Hansson
    + Top 13 Ruby on Rails Presentations website
    + "Why Ruby On Rails" Video presentation (March, 2007) by gregg
    + Rails Controllers and Routing presentation by Obie Fernandez (RubyEast 2007)
  3. 5521_rails_basics.zip (Unzip it in a directory of your choice and read lab document from /rails_basics/index.html to proceed) (4/10/2009: Installed/done)
  4. * Presentation (PDF: 1 slide per page (OR) OpenOffice file) (53 pages) (4/10/2009: Read twice)
  5. Online Lab/Change Log document (This is the same document you will find in the hands-on lab zip file) (135 pages)
  6. Exercise 0: Start MySQL database server (p.2-11) Found this tutorial: http://www.netbeans.org/kb/docs/ide/mysql.html
  7. (0.1) step 1: Did this instead. Inside netbeans/services tab/databases/right click/register mysql server. On page 5 I filled out Admin Properties with the admin tool at c:/Deep*/Ins*2.0*/mysql/bin/mysqladmin.exe, etc. I left admin password empty as told on page 3.
  8. (0.1) step 2: Test if the MySql database is running (pg. 7). Output: Uptime: 341 Threads: 2 Questions: 689 Slow queries: 0 Opens: 12 Flush tables: 1 Open tables: 6 Queries per second avg: 2.021
  9. Exercise 1: Build and run "helloworld" Rails application (pg. 11-85)
  10. (1.1) Create Ruby on Rails NetBeans project (p.11-19) Note that I used "helloworld", RAILSPASSION directory, Built-in JRuby (1.1.4), and Glassfish to create the "New Ruby on Rails Application" project. Output was: http://www.pastie.org/443997 Looked OK.On page 14, appears that example has more files that my project. Unclear if OKAY or NOT. Appear OK for now.
  11. (1.2) Create Database (p.19-35) Since I am using Netbeans 6.5, I needed to skip pages 19-23). Now on page 24 and 25 I followed the directions (helloworld/"Run/Debug Rake Task"/db:create/Run). Did not get any feedback so repeated it with debug on and got this: Fast Debugger (ruby-debug-ide 0.3.1) listens on localhost:63550
    (in C:/cygwin/home/jasnow/RAILSPASSION/helloworld)
    helloworld_development already exists
  12. (1.2) step 2: page 27: To verify existance of helloworld_development, I had to use Refresh.
  13. (1.3) Create Model. (page 35-45) On page 38, I ran Rails Generator for Model and got this: JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    exists app/models/
    exists test/unit/
    exists test/fixtures/
    create app/models/message.rb
    create test/unit/message_test.rb
    create test/fixtures/messages.yml
    create db/migrate
    create db/migrate/20090412003007_create_messages.rb
  14. (1.4) Create database table through migration (p.45-55) Followed directions on page 48 to migrate to Current Version and got this: (in C:/cygwin/home/jasnow/RAILSPASSION/helloworld)
    == 20090412003007 CreateMessages: migrating ===================================
    -- create_table(:messages)
    -> 0.0727s
    == 20090412003007 CreateMessages: migrated (0.0732s) ==========================
  15. (1.5) Create a Controller (p.55-62)
  16. (1.5) step 1 (pg.56) Used Rails Generator to generate Controller and got this: JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    exists app/controllers/
    exists app/helpers/
    create app/views/hello
    exists test/functional/
    create app/controllers/hello_controller.rb
    create test/functional/hello_controller_test.rb
    create app/helpers/hello_helper.rb
  17. (1.6) Write a View (p.62-67) Created a RHTML file and added some text.
  18. (1.7) Set URL routing (p.67-73) Changed "welcome" to "hello" on line 34 of Configuration/routes.rb file. Then deleted index.html under Public directory.
  19. (1.8) Build and run the application (helloworld). (pg.73-??) Tried to run it and got this: Warning: Cannot open log file: C:\Program Files\glassfish-v3-prelude\glassfish\domains\domain1/logs/jvm.log
    Warning: Forcing option -XX:LogFile=C:\Users\jasnow\AppData\Local\Temp\\hs_pid7316.log
    INFO: Launching GlassFish on Apache Felix OSGi platform
    Welcome to Felix.
    =================
    ERROR: org.apache.felix.framework.cache.BundleCache: Unable to create directory: C:\Program Files\glassfish-v3-prelude\glassfish\domains\domain1\.felix\gf
    INFO: Cannot create record of lastModified file
    Error creating bundle cache:
    java.lang.RuntimeException: Unable to create profile directory.
    at org.apache.felix.framework.cache.BundleCache.initialize(BundleCache.java:353)
    at org.apache.felix.framework.cache.BundleCache.(BundleCache.java:95)
    at org.apache.felix.framework.Felix.(Felix.java:248)
    at org.apache.felix.framework.Felix.(Felix.java:125)
    at org.apache.felix.main.Main.main(Main.java:235)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.enterprise.glassfish.bootstrap.ASMainFelix$1.run(ASMainFelix.java:101)
    at java.lang.Thread.run(Thread.java:619)
  20. So I change "helloworld/Set Configuration/Customize/WEBrick and reran it and got this: => Booting WEBrick...
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    [2009-04-11 21:04:18] INFO WEBrick 1.3.1
    [2009-04-11 21:04:18] INFO ruby 1.8.6 (2008-08-28) [java]
    [2009-04-11 21:04:18] INFO WEBrick::HTTPServer#start: pid=332711452 port=8080
    => Rails 2.1.0 application started on http://0.0.0.0:8080
    => Ctrl-C to shutdown server; call with --help for options
    127.0.0.1 - - [11/Apr/2009:21:04:22 EDT] "GET / HTTP/1.1" 404 570
    - -> /
    127.0.0.1 - - [11/Apr/2009:21:04:23 EDT] "GET /favicon.ico HTTP/1.1" 200 0
    - -> /favicon.ico
    Also got this in the web browser as seen on page 75:
    Unknown action No action responded to index
  21. So I changed the URL to "http://localhost:8080/hello/say_hello" and got this as seen on page 76: My greeting message is Hello World!
    The current time is Sat Apr 11 21:09:17 -0400 2009

  22. Modified hello_controller.rb and typed URL: http://localhost:8080/ and it worked as seen on page 79.

  23. Note that the bottom of page 79 to page 85 are Troubleshooting Solutions.
  24. Exercise #2: Add another field to a Model (p.85-??)
  25. (2.1) Add another field to a table through migration (p.86-93) On page 87 and 88, Generate migration and got this: JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    exists db/migrate
    create db/migrate/20090412012221_add_name.rb
  26. (2.1) Ran "Migrate Database" and got this: (in C:/cygwin/home/jasnow/RAILSPASSION/helloworld)
    == 20090412012221 AddName: migrating ==========================================
    -- add_column(:messages, :name, :string)
    -> 0.1114s
    == 20090412012221 AddName: migrated (0.1121s) =================================
  27. (2.2) Modify the controller (p.94-95) Added a line to Controllers/hello_controller.rb.
  28. (2.3) Modify the view. (pg. 96-97) (SO step 2.2 stuff can be seen in the browser)
  29. (2.4) Save the changes and Refresh the browser (p.98-100) IT WORKED.
  30. (2.5) Display log file (p.101-102) Opened up Logs/development.log. WORKED.
  31. (2.6) Modify the view (p.103-106) Added code and refreshed browser. IT WORKED.
  32. Exercise #3: Add another template to the application (p.106-??)
  33. (3.1) Create a new template (p.106-109) Created say_goodbye.html.erb.
  34. (3.2) Modify existing template (p.110-112) Changed say_hello.rhtml.
  35. (3.3) Add a new section (p.113-116) Add a new section to hello_controller.rb.
  36. (3.4) Save all changes and refresh the browser (p.115-118) IT WORKED.
  37. Exercise #4: Build and run "helloname" application (p.121-??)
  38. (4.1) Create Ruby on Rails NetBeans project (p.121-122) DONE
  39. (4.2) Create database (p.122) DONE
  40. (4.3) Create model (p.122-123) DONE
  41. (4.4) Migrate the database (p.123) DONE
  42. (4.5) Create a Controller (p.124-125) DONE
  43. (4.6) Write templates (p.125-127) DONE
  44. (4.7) Set the URL routing and delete index.html (p.127-129) DONE
  45. (4.8) Build and run the application (p.129-131) NOTE that pages 132-134 are TROUBLESHOOTING pages.
  46. Finished 10:19pm. Started at 6:55pm. => 3.5 hours or 210 minutes
  47. Homework Exercise (p.134-135)
  48. (AL#1) Created project: studentapp, with Jruby and WEBrick. (WORKED)
  49. (AL#2) Created 3 databases. (done/verified under Services)
  50. (AL#3) Connected to step 49's development database. (done)
  51. (AL#4) Create Student model with 2 attributes: name:string and age:integer.
  52. (AL#5) Migrated database to Current version. (done)
  53. (AL#6) Create Ask controller. (done)
  54. Finished it.