1
votes

I am using ember cli with ember data and have been piecing together information but it still doesn't work. This all involves the Home model, route and template. I feel like I'm close but still no cigar. I took everything out except for the title to simplify it. According to documentation I've read, everything is as it should be.

here is my app.js

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

Ember.MODEL_FACTORY_INJECTIONS = true;

var App = Ember.Application.extend({
  modulePrefix: config.modulePrefix,
  podModulePrefix: config.podModulePrefix,
  Resolver: Resolver
});

loadInitializers(App, config.modulePrefix);

export default App;

Here is my home model:

 import DS from 'ember-data';

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

    Home.reopenClass({
    FIXTURES :[
    {
     id: 1,
     title: 'Sponge B',
    }, 

    {
    id: 2,
    title: 'John David',
    }, 

    ]
    });

Here is my home route:

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

    export default  Ember.Route.extend({
         model: function(){
            return this.store.find('Home');
        },
    });

This is my home template:

   <div id="home"> 
    {{#each}}
    <p>{{title}}</p>
    {{/each}}
   </div>
   {{outlet}}

Could someone please help me out?

I think it has something to do with my model hook. Could this also be a controller issue. I generated a basic controller. Should I have generated an arrayController?. The home route when saved gives me this error message: models/home.js: line 9, col 1, 'Home' is not defined. but when I define it there still is a problem. Am I supposed to ad a folder called adapters, then put a file in it called application.js, then ad export default DS.FixtureAdapter.extend(); . But when I do that it tells me DS is not defined

3

3 Answers

0
votes

It looks like you are explicitly exporting your model as Home and then you are trying to find('home') which does not have the same letter case.

Ember will not automatically resolve the case for you. If you want to use Home as the model, you will need to call it in the same way every time.

You might even need to import Home from '../models/model-file'; if you want to call it from the route..

An easier thing to try would be to use the implicit export default Ember.Model.extend({}) and let ember-cli resolve the class using your file name.

http://www.ember-cli.com/#using-modules

0
votes

Your template seems to be the issue. You reference an item property that isn't there:

<div id="home">
    {{#each}}
    <p>{{title}}</p>
    {{/each}}
</div>

Also, you have some syntax problems with your model. Try this:

import DS from 'ember-data';

var Home= DS.Model.extend({
  title         : DS.attr('string'),
});

Home.reopenClass({
  FIXTURES :[
    {
     id: 1,
     title: 'Sponge B',
    }, 

    {
    id: 2,
    title: 'John David',
    }, 
  ]
});
export default Home;
0
votes

For the Fixture Adapter you are correct in adding the application.js to the adapters folder and import DS from 'ember-data'.

Also in Steve H's example of your home model, the definition of the FIXTURES is not correct. Try using: Home.FIXTURES = [ ... ];

Make sure the pathing is correct.