To Lecture Notes

IT 231 -- 10/4/12

 

Review Questions

  1. What is the difference between the Rails generate scaffold statement and the Rails generate model statement?
    Ans: The Rails generate scaffold statement creates a new database table together with a controller and the views index, show, new, and edit. The Rails generate model statement only creates the new database table.
     
  2. Write a Ruby line that prints a random number from 0 to 10 with equal probability.
  3. Write a Ruby line that assigns to employee_id, a random number 1001 to 1999 with equal probability.
  4. Modify Example 17 (Overtime Example) to receive input from the keyboard.
    Ans: Replace the statements
    by
  5. Modify Example 19 (ConsultantBSGenerator Example) to display its output in a rails view.
     
    Ans: Put all of this code in the code in the controller. Replace the last statement
    with
    Put this code in the view:
  6. Write a Rails application with a view that randomly displays two of these dice. Also display the sum of the dice.
     

    Use three instance variables @die1, @die2, and @sum, whose values are set in the controller.
    Ans: Create a Rails project named Casino with controller RollDice and view display. Put this method in the controller
    and this code in the display view

 

Some ActiveRecord Method Calls

 

Modifying Images with Image Editing Software

 

Project 4

 

Practice Problems

  1. Write a Ruby script that inputs the course score and outputs the course grade.
    A == 90..100, B == 80..89, C == 70..79, D == 60..69, F == 0..59.
     
  2. Add this method to the Dice class (Example 14) and test it:

  3. Create a Rails project named TestProject. Then do the following:
     
    1. Generate a controller named ShowInfo with one action home.
    2. Add another action named page1.
    3. Define titles in the controller for the views.
    4. Add a stylesheet that
      • sets the background color to silver
      • the text color to maroon
      • the font family to Arial
      • the hyperlinks (link_to) to yellow
      • the size of the h1 tag to 50% larger than the body text
    5. Add a layout page that is compatible with the views.