Exercise Wednesday

Goal: Create an MVC application that uses objects within objects. Pay close attention to how data is passed between routes, views, and forms in an objects-within-objects MVC setup.

Warm Up


  • In the previous lesson, what is the purpose of the Category class? How does it relate to our Item class?
  • How do we pass multiple objects into a View?
  • How does RESTful routing differ when we begin working with objects within objects?
  • Why do we use hidden form fields when creating a new object that resides in another object?

Code


To Do List Continued

Follow along with the homework to add a Category class with the ability to store a list of items to your ongoing to do list.

Music Organizer

Make a program for users to catalog and organize their music. This could be a CD, vinyl or even a tape collection.

  • They should be able to create a new record, enter the record title, and list out all of their records.
  • Add a feature that allows users to add an artist to a record. Keep it simple - assume each is by a single artist.
  • After that, let users list out all the artists and choose an artist to see which records are by that artist.

Further Exploration

Try creating another link on the home page to take the user to a "/search_by_artist" page. Users should be able to fill out a form with an artist name to search for their collection. After submitting the form they should be taken to a page listing out all the records they own by that artist.

Then try to improve the search functionality. If the user has created a record object by "JS Bach," they should be able to search for it by typing in "bach," "Bach," or "Johann Sebastian Bach." Say the user has a record by "Bachman–Turner Overdrive" as well as one by "JS Bach." If the user searches by the name "bach" or "Bach," both the records by "JS Bach" and "Bachman–Turner Overdrive" should be displayed.

Hangman

Make a program to play the Hangman game. Here's a refresher on the rules. Think carefully about the object(s) you'll use before starting. There are multiple ways to solve this problem.

  • The computer can generate the words from a pre-set list.
  • The user can make a Guess by entering a letter into a form. The app should tell them if it's right or wrong, and keep track of how many guesses they have left.
  • Don't worry about graphics. You can use a collection of 6 images. After the user has made a guess, take them to the /hangman page. If the user has one wrong guess, show the first image. If they have 2 wrong guesses, show the second image, etc.
  • On the /hangman page, display the letters they have guessed correctly so far, just like above: b _ b b _ _
  • Also, display the letters they have guessed incorrectly, and how many guesses they have left.
  • Make sure to display messages telling the user whether they've guessed correctly or incorrectly. Then a "Game Over" message if they're out of guesses.
  • Don't allow duplicate guesses. If the user tries to guess the same letter twice they should be told to try again.
  • Try to change the color of an element on your /hangman page based on whether the guess was right or wrong. Play around with changing the layout of your template file based on whether a guess is right or wrong, and whether or not the game is over.
  • Bonus: make it two-player! Create a new form page where one user can choose a word for the other user to guess.

Go Fish

Make a game where two people can play Go Fish against each other. Here is a refresher on the rules.You will need to create a Game class and a Player class, which should at least hold the player's hand of cards. If you are feeling ambitious, you can also try creating a single-player mode where one user can play against the computer.

Peer Code Review


  • Are there two classes in the application?
  • Can a user input a new nested object and see it displayed on the parent object's detail page?
  • Can a user select an object and see the objects associated with it?
  • Is code DRY and functional?

Lesson 10 of 11
Last updated more than 3 months ago.