To Examples

MovieReviewSite Directions

 

  1. Open a command window.
     
  2. Navigate to your folder for rails applications.
     
  3. Create a new rails project named MovieReviewSite:
    > rails new MovieReviewSite
     
  4. Navigate to the MovieReviewSite folder.
     
  5. Create the project using scaffolding:
    > rails generate scaffold MovieReview reviewer:string review:text movie_release_date:date rating:float
     
  6. Build the database table:
    > rake db:migrate
     
  7. Start the Rails server:
    > rails s
     
  8. In a browser navigate to this URL:
    > http://localhost:3000/movie_reviews
     
  9. Enhance your MovieReviewSite project by making these changes to the project:
     
    1. Change the years displayed in the movie_release_date field:   In the file app/views/movie_reviews/_form.html.erb, line 23, replace the line
        <%= f.date_select :movie_release_date %>
        
      by
        <%= f.date_select :movie_release_date,
            :start_year => 1996, :end_year => 2006 %>
        
    2. Add the following validations:   Add these lines of code to the file app/models/movie_reviews.rb:
        validates_presence_of :reviewer
        
        validates_numericality_of :rating,
            :greater_than_or_equal_to 0.0,
            :less_than_or_equal_to 5.0
        
    3. Add a heading to the show view:   Add the following header to the file app/views/movie_reviews/show.html.erb:
        <h1>Movie Review Information</h1>
        
    4. Change the heading on the index view:   Change this code in the file app/views/movie_reviews/index.html.erb:
        <h1>Listing movie_reviews>
        
      to
        <h1>Movie Review Listings</h2>
        
    5. Change the table headings on the index view:   Change the table headings in the th tags to be more descriptive and user friendly.
       
    6. Change the labels on the form:   Change the labels in the form file app/views/movie_reviews/_form.html.erb to make them more user friendly. For example, in line 15, change the line
        <%= f.text_field :reviewer %>
        
      to
        <%= Reviewer Name %>