To Lecture Notes

IT 231 -- 10/18/12

Review Questions

  1. Explain what these lines do in show.html.erb of Example 23?
    Ans: Line a says that the data values in any control in the form (between lines a and d) will be submitted back to the controller method corrsponding to the action convert. Line b defines the text field control as having the name :celsius and initial value @c. Line c says that the caption on the submit button is Convert Temperature. The form is submitted to the controller when the submit button is clicked. Line b terminates the form. A different IRB delimiter is used for the end statement because end is a control statement and does not generate any HTML code on the client end.
     
  2. Explain what these lines do in convert_controller.rb of Example 23:
    Ans: (a) params[:cel] obtains the string from the :cel control and assigns it to the local variale input. (b) Assigns input converted to an integer to the instance variable @c. (c) Converts @c to Fahrenheit and assigns it to the instance variable @f.
     
  3. How do you identify a Rails symbol?
     
    Ans: A symbol starts with a colon ( : ). It is used for the names of controls and also for the names of optional parameters.
     
  4. Suppose that you have entered the controller source code and the view source code in convert.html.erb correctly. The page displays correctly, but when the submit button is clicked, the error message "No such route [POST] /temp_converter/convert" is displayed. What is wrong?
     
  5. Ans: You may not have entered a new post route in config/routes.rb:
  6. Why should you test frequently when typing in code for the controller and views?
     
    Ans: Because if you type in everything first, you will probably make many errors and they will be difficult to fix. If you type in a little at a time, the errors will be easier to find.
     
  7. What is the HTML tag name and type attribute for each of these controls:
     

    Ans:
     
    Control Tag Name type attribute
    Text Field input text
    Submit Button input submit


  8. Why is a form tag required whenever you want to send data from a page back to the controller?
     
    Ans: Because a form tag is required in the generated HTML code. This is the way that HTTP manages data that is being sent back to the server.
     
  9. Modify the ChineseZodiac Example (Examples 20) so that it accepts the year in a dropdown box and displays the verses of the song in the browser.
     
    Note: there is a separate set of helper methods called the FormHelper methods that are similar to the FormTagHelper methods, but which are designed to work closely with a database created with a model statement. We will use FormHelper methods for Project 5.

 

The Array each Method

 

Hex Color Codes

 

The Range Class

 

Project 5

 

FormHelper vs. FormTagHelper Methods

 

Examples of Forms Using FormHelper Methods