To Lecture Notes

IT 231 -- 11/1/12

 

Review Questions

  1. What does a one-to-many relationship do for you?
    Ans: Suppose that the primary model is Student and the secondary model is Award. The one-to-many relationship gives for each Student object @s, an array @s.awards that contains all the awards that @s obtained. For each Award object @a, the one-to-many relationship gives @a.student, which is the student to which the award belongs.
     
  2. Suppose you have the one-to-many relationship with primary model Flight and secondary model Passenger.
     
    1. If @p represents a passenger, give an expression that returns the flight number on which that passenger is booked.
        @p.flight.number
        
    2. If @f represents a flight, give an expression that returns the array of all passengers booked on that flight.
        @f.passengers
        
    3. If @f represents a flight, give an expression that returns the number of passengers booked on that flight.
        @f.passengers.count
        
    4. If @f represents a flight, write ERB for a view that lists the names of all the passengers on the flight in a paragraph. The names should be separated by commas.
        <p>
        <% @f.each do |p| %>
        <%= p.name %>,
        <% end %>
        </p>
        
    5. If the photo of passenger @p has the filename @p.photo and the photo is stored in assets/images, write ERB code to display an HTML table of the passenger names and photos of all passengers on the flight @f.
        <table>
        <% @f.each do |p| %>
        <tr> <td> <%= p.name %> </td> </tr> 
        <tr> <td> <%= image_tag p.photo %> </td> </tr> 
        <% end %>
        </table>
        
  3. Build Example 32.5 (PetSalon Example).

 

Searching and Sorting

 

Crptypographic Hash Functions

 

Maintaining State