0
votes

I have an ember cli app (v1.10) that uses a restadapter in the adapter/application.js. I'm adding several sections to the app but the services are not written yet and I want to use fixtures with faux data in them to build everything out. In my first attempt, I cannot seem to integrate sections with different an adapter type different than the one in application.js. According to the console error, the app when I go to #/assessments keeps trying to make an api call even though the assessments adapter is using FixtureAdapter. Is this a common problem/ limitation in ember cli?

router.js

Router.map(function() {
    this.resource('assessments', function() {
        this.route('publish');        
    });
});

models/assessments.js--

import DS from 'ember-data';


var Assessments = DS.Model.extend({
    clientId: DS.attr(),
    clientName: DS.attr('string'),
    envId: DS.attr(),
    envName: DS.attr('string')
});

Assessments.reopenClass({
    FIXTURES: [
        {   
            id: 1,
            clientId: 1,
            clientName: 'a',
            envId:10,
            envName: 'Production'
        },
        {
            id: 2,
            clientId: 2,
            clientName: 'b',
            envId:11,
            envName: 'Dev'
        },
        {
            id: 3,
            clientId: 1,
            clientName: 'a',
            envId:12,
            envName: 'Lab'
        } 
    ]
});

export default Assessments;

routes/assessments.js

import Ember from 'ember';

export default Ember.Route.extend({

    model: function(){
        return this.store.find('assessments');
    }
});

Any assistance is much appreciated!

adapters/assessments.js

import DS from "ember-data";

export default DS.FixtureAdapter.extend({});
1
There's a chance that it could be naming related. If you have the Ember Developer tools installed, you could grab the instance of your controller and try running this.container.lookup('adapter:assessments') and this.container.lookup('adapter:assessment') to see if either of those return your adapter. I'm guessing the former will and the latter won't but Ember is trying the latter.Justin Niessner
Hey justin, i have the ember inspector tool installed. where would you recommend i put these lines of code? thanks for your help!campatsky
If you use the tool to view the structure of your application, you should see an $E next to the Application Controller. You can then use the console to run $E.get('container').lookup('adapter:assessment'). For future reference, Ember expects singular names for everything.Justin Niessner
okay cool. i'll give that a try right now. what do you mean by singular names?campatsky
oh, interesting. do all files in the app need to be singular or just the models and adapters?campatsky

1 Answers

1
votes

TL;DR

Things are failing because Ember is trying to find an adapter for Assessment rather than Assessments. Rename things in the singular and you'll be good to go.

Long Explanation

Ember CLI has strong opinions about how you should be laying things out. One of those opinions is that things should be named in the singular. Currently, you're naming things in the plural and things are getting thrown off.

If you install the Ember Inspector for Chrome, grab the ApplicationController, and try the following, you should get those results:

var container = $E.get('container');
console.log(container.lookup('adapter:assessments')); // should get something
console.log(container.lookup('adapter:assessment')); // should be undefined

Unfortunately, Ember is trying to perform the lookup using the singular (its internal code singularizes things to match its expectations).

If you rename your models/controllers/adapters/etc. to be singular, everything should line up and magically work for you.