Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Ember.js Models Challenge: Individual Objects

Steven Byington
Steven Byington
13,584 Points

Wrong answer for model challenge

The challenge asks "We've set up a router with a couple resources for you, as well as a puppies variable with some model data. Create a puppy route that loads the correct puppy based on the ID in the URL."

Here is the answer I gave, but it says it is wrong. The alert says I need to pass the post_id into the second argument. Shouldn't it be puppies_id like I had put?

AnimalShelter = Ember.Application.create();

AnimalShelter.Router.map(function() {
  this.resource('puppies', {path: '/'});
  this.resource('puppy', {path: 'puppies/:puppy_id'});
});

var puppies = [
  {id: '1', name: 'Miss Puggy'},
  {id: '2', name: 'Pugsley Addams'},
  {id: '3', name: 'Chicken Pug Pie'}
]

AnimalShelter.PuppyRoute = Ember.Route.extend({
  model: function(params) {
    return puppies.findBy('id', params.puppy_id);
  }
});

5 Answers

Michael Kaiser-Nyman
STAFF
Michael Kaiser-Nyman
Treehouse Guest Teacher

Hi Steven! Thanks for the heads up. Your solution is, indeed, correct. It looks like the challenge isn't set up properly. I've asked Treehouse to help out with getting that fixed. Thanks for finding the problem and pointing it out!

I hope you're enjoying the course so far.

Here's the answer to the kittens question below:

Question: In app.js, we've set up a variable named kittens with some data in it. Set up KittensRoute to use this data for the model.

Answer:

AnimalShelter = Ember.Application.create();

AnimalShelter.Router.map(function() { this.resource('kittens', {path: '/'}); });

var kittens = [ {id: '1', name: 'Meowzer'}, {id: '2', name: 'Squeaky'}, {id: '3', name: 'Fluffy'} ]

AnimalShelter.KittensRoute = Ember.Route.extend({ model: function() { return kittens; } });

Hey Steven Byington!

You're rightβ€”we had a bug in the code challenge. Your solution (the correct solution) is now properly accepted. Try again and all will be right in the world.

I also awarded you the Exterminator badge for being awesome and squashing bugs.

:zap:

jadaml
jadaml
11,593 Points

Kyle Meyer It does not appear to be working yet. As my code below appears to be the same and is failing.

AnimalShelter.PuppyRoute = Ember.Route.extend({
  model: function(params) {
    return puppies.findby('id', params.puppy_id);
  }
});

I had the same result using the code examples from the video. The trick is to use findBy instead of findby.

Since this was from 3 months ago, I assume you figured it out by now. However, for anyone else that might be your problem.

Sorry to hear you were having trouble jadami,

but Steven Byington's code worked for me. :thumbsup:

Link to the challenge: http://teamtreehouse.com/library/emberjs/models/challenge-individual-objects