Skip to content

Instantly share code, notes, and snippets.

@vanderhoop
Last active August 29, 2015 14:16
Show Gist options
  • Save vanderhoop/1ce75b32dc9d3e915332 to your computer and use it in GitHub Desktop.
Save vanderhoop/1ce75b32dc9d3e915332 to your computer and use it in GitHub Desktop.

The TMNT Villain Collection

You just learned some of the incredible magic and utility of Backbone Collections. Now it's your turn to put them to practical use.

Directions

  1. Create a Backbone Model called VillainModel
  • Provide the VillainModel with defaults (set to null) for the following attributes
    • id
    • name
    • species
    • superpower
  1. Create a Backbone Collection called VillainCollection, and pass it the RESTful url for appropriate for villains, as well as the appropriate model.
  2. Instantiate a VillainCollection, and use .fetch() to breathe sweet, sweet data into it.
  3. Now that your VillainCollection has 4 models within it, retrieve the villain model with id of 4 and save it to a variable called rocksteady.
  4. Awesome, now retrieve the species of the villain model with id of 2. Save it in a variable called speciesOfKrang.
  5. Now retrieve the villain model with id of 1 to a variable called shredder.
  6. Set shredder's superpower to hatred.
  7. Persist the change in shredder's superpower. Validate that the change was made in the database using the Rails console.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment