Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set rest adapter in ember cli generated model

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()
    });
like image 785
MikeV Avatar asked Jul 22 '14 02:07

MikeV


1 Answers

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;
like image 159
ViRa Avatar answered Sep 27 '22 21:09

ViRa