To Lecture Notes

IT 232 -- 10/26/15

Review Exercises

  1. How do you set a background image for a controller?

    Ans: Put this line in the controller SCSS stylesheet:
    body { background-image: url(image.jpg); }
    
  2. How do you designate a view as the home page to be displayed with http://localhost:3000.
    Ans: To set the index page of the Student controller as the home page, put this line in the routes file:
    root 'students#index'
    
    To set the show page with id=7 as the root node:
    root 'students#show', id: '7'
    
  3. What are the steps to adding a new page to an existing controller?
    Ans: If the new view directory is to be added to the students controller,
    1. add the new ERB file directory.html.erb to the views folder,
    2. add a new method named directory to the students controller,
    3. add this route to the routes file:
      resources :students do
        collection do
          get :directory
        end
      end
      
  4. What are the path names for a scaffold-based controller with model name Student? Run rake routes to verify your answer. Ans:
    View Helper Method
    index students_path
    show student_path(@student)
    or
    @student
    new new_students
    edit edit_student(@student)

    Here is the result of running rake routes:
          Prefix Verb   URI Pattern                  Controller#Action
        students GET    /students(.:format)          students#index
                 POST   /students(.:format)          students#create
     new_student GET    /students/new(.:format)      students#new
    edit_student GET    /students/:id/edit(.:format) students#edit
         student GET    /students/:id(.:format)      students#show
                 PATCH  /students/:id(.:format)      students#update
                 PUT    /students/:id(.:format)      students#update
                 DELETE /students/:id(.:format)      students#destroy
    
  5. Translate the following FormTagHelper method calls into FormHelper method calls:
    a.   <%= form_tag convert_display_path do %>
    Ans: <%= form_for @conv_rec, url: convert_display_path do |f| %>
    
    b.   <%= text_field_tag :name %>
    Ans: <%= f.text_field :name %>
     
    c.   <%= submit_tag 'Submit Data' %>
    Ans: <%= f.submit 'Submit Data' %>
    

Examples from Last Week

Project 4

Session Variables

Digests

The Depot1 Example

Photo Model Code