← Back to Upcase

Ember Fundamentals - Your first Model

(Upcase ) #1

This topic is for the Your first Model exercise in the Ember Fundamentals trail. Post any questions, corrections, or pointers you have to share with other Upcase subscribers.

(Jason Duffy) #2

I’m having trouble getting the your-first-model exercise to work, does anyone have any advice on how best to try and figure out where I went wrong? So far I’ve added:

this.route(‘notebook’, { path: “/:id” });

inside the notebooks route function, added

{{#each notebook in notebooks}}
  {{#link-to ‘notebook’}}
    {{notebook.title}}
  {{/link-to}}
{{/each}}

to notebooks.hbs template, created app/routes/notebooks/notebook.js with

model: function(params) {
  return this.store.find(‘notebook’, params.notebook_id);
}

, created app/routes/notebooks.js with

model: function() {
  return this.store.find(‘notebook’);
}

, and created app/models/notebook.js with

title: DS.attr()

My server runs, but I don’t see any notebooks on the left at /notebooks/ and /notebooks/1 gives me Error while processing route: notebooks.notebook Couldn't find record of type 'notebook' for the id '1'. Error: Couldn't find record of type 'notebook' for the id '1’.

I’m sure I’m missing something - or misunderstanding something.

(Jason Duffy) #3

OK, my tests are passing now. I had various problems, I’ll try to list them and maybe they’ll be helpful if others have similar issues.

  • In notebooks.hbs, my model is actually called model and not notebooks.
  • I had to make the notebook route into a resource
  • The link-to needs a reference to the notebook, not just the name of the route
(evan) #4

if you don’t have it already, ember inspector has a model tab that lets you see which model is being loaded on each page. it does all kinds of other cool stuff, like letting you see how the routes and outlets overlay on each other and lets you set internals to $E so you can debug in the console.

(Jason Duffy) #5

I do have ember inspector. It was helpful while trying to figure out what was going on, though I’m not convinced I know how to use it very well yet.