You are here:   ArielOrtiz.com > Software Design and Architecture > Lab 10: Movies

Lab 10: Movies

Objectives

During this lab session:

This activity helps students develop the following skills, values and attitudes: ability to analyze and synthesize, capacity for identifying and solving problems, and efficient use of computer systems.

Activity Description

The lab activities can be developed individually or in pairs.

The lab report must be developed individually.

  1. Create a Ruby on Rails application called moviesapp. Inside this application, generate a scaffold with a model called Movie that has the following columns: name (string), year (integer), and director (string). Also, create manually a file called display.rb inside the moviesapp/script directory.

    Run the migration file in order to create the movies database table.

    The Ruby source files movies_controller.rb and display.rb must start with a comment containing the lab's title, date, and the authors' personal information. For example:

    # Lab 10: Movies
    # Date: 05-Apr-2011
    # Authors:
    # 456654  Anthony Stark 
    # 1160611 Thursday Rubinstein
  2. Create a file called movies_data.sql in the moviesapp/db folder with the following content:

    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ("The King's Speech", 2010, 'Tom Hooper', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('The Hurt Locker Poster', 2009, 'Kathryn Bigelow', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Slumdog Millionaire', 2008, 'Danny Boyle', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('No Country for Old Men', 2007, 'Ethan Coen', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('The Departed',2006,'Martin Scorsese', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Crash',2005,'Paul Haggis', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Million Dollar Baby',2004,'Clint Eastwood', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('LOTR: Return of the King',2003,'Peter Jackson', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Chicago',2002,'Rob Marshall', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('A Beautiful Mind',2001,'Ron Howard', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Gladiator',2000,'Ridley Scott', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('American Beauty',1999,'Sam Mendes', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Shakespeare in Love',1998,'John Madden', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Titanic',1997,'James Cameron', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('The English Patient',1996,'Anthony Minghella', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Braveheart',1995,'Mel Gibson', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Forrest Gump',1994,'Robert Zemeckis', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ("Schindler's List",1993,'Steven Spielberg', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Unforgiven',1992,'Clint Eastwood', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('The Silence of the Lambs',1991,'Jonathan Demme', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Dances With Wolves',1990,'Kevin Costner', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Driving Miss Daisy',1989,'Bruce Beresford', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Rain Man',1988,'Barry Levinson', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('The Last Emperor',1987,'Bernardo Bertolucci', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Platoon',1986,'Oliver Stone', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Out of Africa',1985,'Sydney Pollack', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Amadeus',1984,'Milos Forman', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Terms of Endearment',1983,'James L. Brooks', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Gandhi',1982,'Richard Attenborough', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Chariots of Fire',1981,'Hugh Hudson', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');
    INSERT INTO movies (name, year, director, created_at, updated_at)
    VALUES ('Ordinary People',1980,'Robert Redford', 
            '2011-04-05 12:00:00', '2011-04-05 12:00:00');

    In the moviesapp/db directory, run the following instruction from the command line:

    sqlite3 development.sqlite3 < movies_data.sql

    Run the server, and in a web browser point to http://localhost:3000/movies in order to verify that everything is in its place.

  3. Modify the index and show actions of the MoviesController class so that they are able to render using JSON (additional to HTML and XML).
  4. In the display.rb source file, include the necessary Ruby script code to access the database using RESTful web services via Ruby's net/html standard package and JSON.

    If the script is called without command line arguments, it must display a table like the one shown in the following examples. If an integer is provided as its only command line argument, it displays the information regarding the record with that specific ID. The script must print "Error" in case the provided information in the command line is incorrect.

    Command line arguments can be retrieved in Ruby using the ARGV constant.

    Examples:

    $ ruby script/display.rb
    ----------------------------------------------------
    Year Name                      Director
    ----------------------------------------------------
    2010 The King's Speech         Tom Hooper 
    2009 The Hurt Locker Poster    Kathryn Bigelow 
    2008 Slumdog Millionaire       Danny Boyle
    2007 No Country for Old Men    Ethan Coen
    2006 The Departed              Martin Scorsese
    2005 Crash                     Paul Haggis
    2004 Million Dollar Baby       Clint Eastwood
    2003 LOTR: Return of the King  Peter Jackson
    2002 Chicago                   Rob Marshall
    2001 A Beautiful Mind          Ron Howard
    2000 Gladiator                 Ridley Scott
    1999 American Beauty           Sam Mendes
    1998 Shakespeare in Love       John Madden
    1997 Titanic                   James Cameron
    1996 The English Patient       Anthony Minghella
    1995 Braveheart                Mel Gibson
    1994 Forrest Gump              Robert Zemeckis
    1993 Schindler's List          Steven Spielberg
    1992 Unforgiven                Clint Eastwood
    1991 The Silence of the Lambs  Jonathan Demme
    1990 Dances With Wolves        Kevin Costner
    1989 Driving Miss Daisy        Bruce Beresford
    1988 Rain Man                  Barry Levinson
    1987 The Last Emperor          Bernardo Bertolucci
    1986 Platoon                   Oliver Stone
    1985 Out of Africa             Sydney Pollack
    1984 Amadeus                   Milos Forman
    1983 Terms of Endearment       James L. Brooks
    1982 Gandhi                    Richard Attenborough
    1981 Chariots of Fire          Hugh Hudson
    1980 Ordinary People           Robert Redford
    ----------------------------------------------------
    
    $ ruby script/display.rb 8
    Id       : 8
    Name     : LOTR: Return of the King
    Year     : 2003
    Director : Peter Jackson
    
    $ ruby script/display.rb 42
    Error
    
    $ ruby script/display.rb 12 20
    Error
    
    $ ruby script/display.rb hello
    Error
    

Deliverables

To hand in your individual lab work, follow these instructions.

Due date is Monday, April 11.

Evaluation

This activity will be evaluated using the following criteria:

50% Implementation of functional requirements.
50% Lab report.
DA The program and/or report was plagiarized.
© 1996-2011 by Ariel Ortiz (ariel.ortiz@itesm.mx)
Made with Django | Licensed under Creative Commons | Valid XHTML | Valid CSS