To Lecture Notes

IT 231 -- 9/16/15

Review Questions

  1. Look at the DivTags Example.  This example may be useful for Project 1.
  2. How do you create a Rails scaffold project? Look at the RealEstate Example.
    Ans: To create the scaffold for the RealEstate Example, enter this line at the Command Line Prompt:
    > rails generate scaffold RealEstateListings address:string  ⇓
         city:string property_type:string price:integer  ⇓
         bedrooms:integer bathrooms:integersize:integer year:integer
    
    Note: the RealEstate Example modifies the index view and the CSS styles for it to give it a look inspired by Zillow. Look at this example carefully. It will be useful for Project 2.
  3. How does a Rails scaffold differ from a Rails model?
    Ans: A scaffold creates a database table as well as views for index, show, new, and edit. The fields in the table correspond with the fields shown on the views. Here is a table that
  4. What are the Rails model/scaffold datatypes?
    Ans: Here is a table of these datatypes.
  5. What does rake db:migrate do?
    Ans: It runs the migration files, which update the database table (or create it if it does not already exist.)
  6. How is the Array class used in Ruby? Give some useful methods of each class.
    Ans: The Array class is used to hold a list of object that can be accessed by index. In Rails, an array is used to hold the rows of the database are read from a database table. The items in this array are then displayed in the index view. Here are some useful Array methods:
    sort  length  count (same as length)  each  collect  reverse
    + (concatenate)  [ ] (array lookup)
    
  7. What is the modern notation for specifying an optional parameter in a method call?
    Ans: Don't use the arrow =>
    # Old fashioned notation:
    <%= link_to "IBM", "http://ibm.com", :target => "_blank" %>
    # Modern notation:
    <%= link_to "IBM", "http://ibm.com", target: "_blank" %>
    
  8. How can you correct errors in a Rails model before running db:migrate?
    Ans: Go into the migration file and edit it first. The migration file is found at db/migrate.