Reputation: 8318
The setup:
ember new shop
cd shop
ember install:addon ember-cli-scaffold
ember generate scaffold product name:string available:boolean
ember generate adapter product
I'd like to use http-mock but http://www.ember-cli.com/#ember-data tells me to do this:
ember g http-mock products
After that I use this code to generate two example products:
server/mocks/products.js
module.exports = function(app) {
var express = require('express');
var productsRouter = express.Router();
productsRouter.get('/', function(req, res) {
res.send({
'products': [
{
id: "1",
name: 'Orange',
available: true
}, {
id: "2",
name: 'Apple',
available: false
}
]
});
});
[...]
When I use the command ember server
and browse to http://localhost:4200/products I see nothing.
What am I missing? What else do I have to start or to configure?
Upvotes: 3
Views: 521
Reputation: 11
You will have to do two things... You will need to make changes in your route for each of the pages that will utilize this api and make a call to the data source in your page template. Lets say you have a page called products you will need to make changes to your route....
// routes/products.js
import Ember from 'ember';
export default Ember.Route.extend({
model:function() {
return this.store.findAll('product');
}
});
Also make changes to your template:
// products.hbs
{{#each products in model}}
<li > {{proudct._id}} - {{#link-to 'product' product}}Details{{/link-to}}</li>{{/each}}
Upvotes: 0
Reputation: 8318
To get this thing flying the adapter has to be changed as follows.
app/adapters/product.js
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
'namespace': 'api'
});
Upvotes: 6