1
votes

I created model in models/application.js:

import DS from 'ember-data';

export default DS.Model.extend({
    name: DS.attr('string')
});

And created adapter in adapters/application.js:

import Ember from "ember";
import DS from 'ember-data';

export default DS.RESTAdapter.extend({
    host: 'http://site.work/rest/v1/'
});

Route in routes/application.js:

import Ember from 'ember';
export default Ember.Route.extend({
    model: function () {
        return this.store.all('application');
});

Template in templates/application.hbs

{{#each item in model}}
<li>{{item.name}}</li>
{{/each}}

app.js

import Ember from 'ember';
import Resolver from 'ember/resolver';
import loadInitializers from 'ember/load-initializers';

Ember.MODEL_FACTORY_INJECTIONS = true;

var App = Ember.Application.extend({
  modulePrefix: 'chat', // TODO: loaded via config
  Resolver: Resolver
});

loadInitializers(App, 'chat');

export default App;

router.js

import Ember from 'ember';

var Router = Ember.Router.extend({
  location: ChatENV.locationType
});

Router.map(function() {
    this.route("application");
});

export default Router;

JSON example from the server: {"application":[{"id":"1","name":"qwe"},{"id":"2","name":"qwe2"}]}

But my model is empty and I can't find any xhr requests in developer tool.

How should I use DS.RESTAdapter in Ember Cli?

Note: When I add this line into router it's works:

this.store.push('application',{'id':5, 'name':'Is this a question?'});
1
Well, are you doing anything that would actually cause a network request? They don't happen by magic.user663031
ember-cli build application and should customize adapter like in this guide emberjs.com/guides/models/customizing-adaptersuser1156168
What I am asking, is do you have a route defined which will request a model which will actually instigate the network request?user663031
yes, I have route application and with line return this.store.all('application');user1156168
this.store.all will not make any requests. Read the manual.user663031

1 Answers

2
votes

I'm not sure if the name of your model (application) is causing weird behaviour, since ember(-cli) also uses this name as root for things such as adapter, route, etc.

Apart from that, I would define my adapter as follows:

import DS from 'ember-data';

export default DS.RESTAdapter.extend({
  namespace: 'rest/v1'
});

and then start your server with:

ember server --proxy=http://site.work