How to set rest adapter in ember cli generated model

MikeV picture MikeV · Jul 22, 2014 · Viewed 7.3k times · Source

I am trying to get my ember model to use a remote rails api. I've tried extending DS.RESTAdapter but I don't know how to tell the model to use those settings. My model never reaches out to localhost:3000.

    //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: 'friend-ember-app', // TODO: loaded via config
      Resolver: Resolver
    });
    App.ApplicationAdapter = DS.RESTAdapter.extend({
        host: 'localhost:3000',
        namespace: 'api/v1'
    });

    loadInitializers(App, 'friend-ember-app');

    export default App;

//

    //models/event.js
    import DS from 'ember-data';

    export default DS.Model.extend({
        title: DS.attr('string'),
        description: DS.attr('string')
    });

//

    // controllers/index.js 
    import Ember from 'ember';

    export default Ember.Controller.extend({
        columns: function(){
            //Attempting to see request to remote api
            var events = this.store.all('event');
            debugger;
            return [1,2,3,4];
        }.property()
    });

Answer

ViRa picture ViRa · Jul 22, 2014

The adapter needs to be defined and exported in a separate file in adapters folder

In adapters/application.js

import DS from "ember-data";

var ApplicationAdapter = DS.RESTAdapter.extend({
    host: 'localhost:3000',
    namespace: 'api/v1'
});

export default ApplicationAdapter;