To Exam Info

IT231 -- Final Review Questions

 

  1. Define these terms:

    See the course notes for these definitions.
     
  2. How do you attach a CSS class to a control?
     
    Ans: With :class => 'ctrl' where .ctrl is defined in the CSS file.
     
  3. What types of validation are available in Rails?
     
    Ans: presence, length, numericality. There are others that we did not discuss.
     
  4. How do you execute a Ruby script from the Rails console?
     
    Ans: load 'rubyfile.rb'
     
  5. Explain the difference between FormTagHelper and FormHelper methods.
     
    Ans: FormTagHelper methods are meant to be used without a database; the controls created by FormHelper methods correspond to the fields of a table in a database.
     
  6. Explain the difference between the following: for, each, collect.
     
    Ans: for and each are used to repeat a calculation or operation for each element in an array or range. collect repeats a calculation for each element of an array, then collects all these calculations together into a new array.
     
  7. What are the the database manipulation methods available from a model?
     
    Ans: find, all, new, save, delete, delete_all, count
     
  8. How do you pass data from a view to a controller?
     
    Ans: With params statements.
     
  9. What are the 17 HTML colors and their hex color codes?
     
    Ans: red #FF0000, lime #00FF00, blue #0000FF, yellow #FFFF00, aqua #00FFFF, fuschia #FF00FF, maroon #800000, green #008000, navy #000080, olive #808000, teal #008080, purple #800080, black #000000, white #FFFFFF, gray or grey #808080, silver #C0C0C0.
     
  10. What is a websafe color?
     
    Ans: Colors all of whose color components consist of 00, 33, 66, 99, CC, or FF.
     
  11. (Find the errors) Read the directions for this problem. Then find the errors in the source code.
     
    1. Generate a controller named website with three views a logon page, a register page, and an index page. Create a layout named website.html.erb that is applied to the three views.
       
    2. Create a model named Login with two fields: username and password.
       
    3. How do you use conditions for the find method?
       
      Ans: a = Student.find(:all, :conditions => "name = 'Jason'")
       
    4. Here are the specs for the three pages:
       
      1. The register page that contains three text fields for username, password, and verification password (FormHelper methods). If the password and verification password match, enter the password in the database. For extra credit, enter the encoded password using SHA1.
         
      2. A login page that takes the user to the index page if the login is successful. Include a link to the register page.
         
      3. An index page that redirects to the login page if a successful login has not occured. Include a link to the register page.

  12. Here are the errors on the pages . See Example 31 for the corrected version.
     
  13. (Computer problem) Generate a controller with two pages. Use a common layout for the two pages: page1 and page2. Specify the titles and headings of the pages in the controller. Specify today's date on each page in the form 11/16/2010.
     
    page1 should contain a text field labeled Name and a submit button with caption Enter Name (use FormTagHelper methods). When the button is clicked, go to page2 and display the greeting "Hello, Alice." (Assume that the name entered was Alice.)
     
    See Example 32 for the answer.
     
  14. (Computer problem) Do not use a scaffold for this problem. Create a model with name Kid, fields name:string, gender:string, gender:integer. Create a controller named KidInfo with two pages preload and display:
     
    1. preload does not contain any controls. It preloads the database with the following information:
       
      Kim F 8
      Jason M 10
      Emma F 7
      Tyler M 9
      Sophia F 11

    2. display displays the contents of the table in a table.

    3.  
    See Example 33 for solution.