I was following the ember Super Rental 3.15 tutorial, when I got to the working with data section, I updated the route index file with model hooks, the page stopped working. Also I am finding ember tutorials to be incomplete.
error says property of map is undefined code in routes index.js file:
import Route from '@ember/routing/route';
const COMMUNITY_CATEGORIES = [
'Condo',
'Townhouse',
'Apartment'
];
export default class IndexRoute extends Route {
async model() {
let response = await fetch('/api/rentals.json');
let { data } = await response.json();
return data.map(model => {
let { attributes } = model;
let type;
if (COMMUNITY_CATEGORIES.includes(attributes.category)) {
type = 'Community';
} else {
type = 'Standalone';
}
return { type, ...attributes };
});
}
}

Your problem is that
fetch('/api/rentals.json');does not return the correct data. And so when you dolet { data } = await response.json();thendatawill beundefinedand you can not doundefined.map.So the code you posted is correct. The problem is somewhere else. You can check:
rentals.jsonfile? If you openhttp://localhost:4200/api/rentals.jsondo you see the data? So have you done this?mirage. Thesuper-rentalstutorial does not usemirage. I can see this here (sidenote: that git repo is automatically created from the guides, so its always up to date). So this could be your problem. Depending how you configure mirage it will basically mock all yourajaxrequests. This means thatfetch(...will no longer work then expected, mirage assumes you always want to use mocked data and you did not configure mirage correctly. You can try to remove mirage from yourpackage.json, rerunnpm install, restart theember serverand try it again.