I’m setting up a basic app using ember-cli and am running into trouble with the api-stub with ember-data. I’ve referenced the api-stub README and have referenced the ember guides, but can’t figure out what I’m missing. I’m a bit of a noob, so forgive any obvious oversights on my part.
Here’s my setup…
/api-stub/routes.js
server.get('/listings', function(req, res) {
var listing = {
"listing": [{
"id": 1,
"title": "Sunny 1-bedroom",
"unit_type": "1br / 1ba",
"description": "Roomy 1-bedroom apartment in pre-war walkup. Gets great morning light from the south."
},
{
"id": 2,
"title": "Large 2-bedroom",
"unit_type": "2br / 1.5ba",
"description": "Roomy 2-bedroom apartment in pre-war walkup. Gets great morning light from the south."
}]
};
res.send(listing);
});
/app/adapters/application.js
var ApplicationAdapter = DS.RESTAdapter.extend({
namespace: 'api'
});
export default ApplicationAdapter;
/app/router.js
this.resource('listings', function() {
this.resource('listing', { path: '/:listing_id' });
});
/app/routes/listings.js
var ListingsRoute = Ember.Route.extend({
model: function() {
return this.store.findAll('listing');
}
});
export default ListingsRoute;
/app/models/listing.js
var attr = DS.attr,
hasMany = DS.hasMany,
belongsTo = DS.belongsTo;
var Listing = DS.Model.extend({
title: attr(),
unit_type: attr(),
description: attr()
});
export default Listing
/app/templates/listing.hbs
<h2>{{title}}</h2>
<p>{{unit_type}}</p>
<p>{{description}}</p>
In console it shows a 404 for …/api/listings and ember inspector in chrome is showing no records.
Any help much appreciated!
I’ve also put this up on Stackoverflow, and will make sure to cross post any answers.