To Lecture Notes

IT 231 -- 7/25/12

 

Review Questions

  1. Explain the difference between the Rails helper functions yield and render.
    Ans: yield embeds a view within a layout page; render inserts code from another file into a view. A file containing code to be inserted with render must be preceded by a leading underscore character. For example, <%= render 'page' %> will insert the contents of the file _page.html.erb.
     
  2. What is the filename containg the code that the following render command inserts?
  3. How do you change the years displayed in a dropdown box for specifying a date on the form _form.html.erb?
    Ans: This answer is shown for the MovieReviewSite Example. Change Line 24 from
    to
  4. How do you specify these validations?
     
    1. The field :owner must be nonempty. Ans:
        validates :owner, :presence => true
        
    2. The field :password must have a minimum length of 8. Ans:
        validates :password, :length => { :minimum => 8 }
        
    3. The field :number_of_guests must be a number that is less than or equal to 4. Ans:
        validates :number_of_guests, :numericality => 
           { :less_than_or_equal_to => 4, :only_integer => true }
        
  5. What does the Rails database console do for you? How can you invoke it?
    Ans: Use the Rails database console to issue SQL commands. Invoke the database console from the DOS Command Prompt.
  6. Name are some important HTTP commands?
    Ans: GET, HEAD, POST, PUT, DELETE.
     
  7. Explain the difference between an HTTP GET request and an HTTP POST request.
    Ans: A GET request passes data back to the server in the URL; a POST request passes back the data in the head section of the page. Rails only uses POST to send information back the server.
     
  8. What does CRUD mean?
    Ans: It is an acronym for the usual database operations: Create, Read, Update, and Destroy.
     
  9. What does REST mean for describing server-side web processing?
    Ans: REST means Representational State Transfer. It means that
    1. A client-server architecture is used.
    2. Stateless communication. This means that neither the controller or the views remember the information on previously submitted views.
    3. Only the HTTP commands GET, POST, PUT, and DELETE are used to communicate with the server:
      CRUD Term HTTP Command
      Create POST
      Read GET
      Update PUT
      DestroyDELETE


     
  10. How do you change the port number to 3726 for the WEBrick server? Ans:
  11. What is the range of numbers for the for well-known ports?
    Ans: 0 to 1023
     
  12. Write a Hello World Ruby program. Ans:
  13. Write a Ruby assignment statement that assigns 256 to the grand total. Ans:
  14. List six ways of executing Ruby statements? Ans:
     
    1. Using Interactive Ruby (IRB).
       
    2. As a Ruby batch script (ruby filename.rb).
       
    3. Using the Rails console (rails console).
       
    4. Loading a Ruby file to run in the Rails console (load filename.rb).
       
    5. Running Ruby code in the controller.
       
    6. Using Embedded Ruby (.erb file) to run the Ruby code in a view.

 

Routing

 

Ruby Details

 

Classes and Objects

 

More about Ruby

 

Project 3