0

I am building an ember app and am attempting to connect to a rails API, to read in data from a questions end point.

These are two separate applications.

My Code is as follows:

adapters/application.js

import DS from 'ember-data';
import ActiveModelAdapter from 'active-model-adapter';

export default DS.ActiveModelAdapter.extend({
  host: 'http://localhost:3000/api/v2'
});

models/questions.js

import DS from 'ember-data';

export default DS.Model.extend({
  text:  DS.attr('string'),
  title: DS.attr('string'),
  debateTopicId:  DS.attr('string'),
  releaseAt: DS.attr('date'),
  expiresAt:  DS.attr('date')
});

routes/questions.js

import Ember from 'ember';

export default Ember.Route.extend({
  model: function() {
    return this.store.findAll('question');
  }
});

templates/questions.hbs

<h2>This is the Questions Feed</h2>

{{#each model as |question|}}
  <h3>{{question.id}} - {{question.text}}</h3>
{{/each}}

The end point I am attempting to call to is:

http://localhost:3000/api/v2/questions

I get the error:

ember.debug.js:19746 Error: Failed to create an instance of 'adapter:application'. Most likely an improperly defined class or an invalid module export.
    at instantiate (ember.debug.js:1477)
    at lookup (ember.debug.js:1336)
    at Object.lookup (ember.debug.js:1255)
    at Class.lookup (ember.debug.js:34526)
    at ContainerInstanceCache.instanceFor (container-instance-cache.js:62)
    at ContainerInstanceCache._findInstance (container-instance-cache.js:51)
    at ContainerInstanceCache.get (container-instance-cache.js:39)
    at Class.retrieveManagedInstance (store.js:2105)
    at Class.lookupAdapter (store.js:2111)
    at Class.adapterFor (store.js:2051)

Any ideas what the issue is?

Steve_D
  • 545
  • 2
  • 11
  • 20
  • Are you properly installing and importing the [active model adapter](https://github.com/ember-data/active-model-adapter)? – Patsy Issa Sep 08 '16 at 07:26
  • I installed the active model adapter and added it too the adapters/application.js file ( edits made to code above ). Im still getting the same error, and other ideas? – Steve_D Sep 08 '16 at 13:31
  • You need to remove the DS from DS.ActiveModelAdapter – Patsy Issa Sep 08 '16 at 13:33
  • That worked I am now hitting the server, however I am now getting a new error, ember.debug.js:19746 Error: Ember Data Request GET http://localhost:3000/api/v2/questions returned a 0 Payload (Empty Content-Type)... Any ideas? – Steve_D Sep 08 '16 at 13:49
  • You were trying to import a module that does not exist, the active model adapter was extracted out of ember data a long time ago, when you installed the addon you imported the correct module but you were still looking for it on the `DS` module. – Patsy Issa Sep 08 '16 at 13:51

0 Answers0