Search code examples
ember.jsember-dataember-cli

Ember CLI - Fixture data not displaying


I am following this guide http://emberjs.com/guides/models/the-fixture-adapter/

I am simply trying to display a list of my fixture data in the personalities resource route. What am I doing wrong?

The browser console error is:

Error while processing route: personality.index attr is not defined ReferenceError: attr is not defined


As soon as I try to obtain the model in my route, the the template no longer renders.

routes/personalities.coffee

`import Ember from 'ember'`

PersonalitiesRoute = Ember.Route.extend
  model: ->
    this.get(store).find('personality')

`export default PersonalitiesRoute`

The above is the portion of code that breaks the app (compiles, but displays nothing). What am I doing wrong?

I have my adapter, template, and model as follows

I made sure to use a fixture adapter adapters/application.coffee

`import DS from 'ember-data'`

ApplicationAdapter = DS.FixtureAdapter.extend()    

`export default ApplicationAdapter`

adapters/personalities.coffee

`import ApplicationAdapter from './application'`

PersonalitiesAdapter = ApplicationAdapter.extend()
    #I also tried... = DS.FixtureAdapter.extend()
    #I also tried getting rid of PersonalitiesAdapter
    #I also tried PersonalityAdapter (singular, since that matches the model, which is singular)

`export default PersonalitiesAdapter`

I tried using various settings I could think of for the personalities adapter as well, to no avail.

models/personality.coffee

`import DS from 'ember-data'`

Personality = DS.Model.extend
  id:           attr('number')
  type:         attr('string')
  socType:      attr('string')

Personality.reopenClass
  FIXTURES: [
    { id: 1,  type: 'entp', socType: 'NLE' }
    { id: 2,  type: 'isfp', socType: 'SFI' }
    { id: 3,  type: 'esfj', socType: 'ESE' }
    { id: 4,  type: 'intj', socType: 'LII' }
    { id: 5,  type: 'enfj', socType: 'EIE' }
    { id: 6,  type: 'istj', socType: 'LSI' }
    { id: 7,  type: 'estp', socType: 'SLE' }
    { id: 8,  type: 'infp', socType: 'IEI' }
    { id: 9,  type: 'esfp', socType: 'SEE' }
    { id: 10, type: 'intp', socType: 'ILI' }  
    { id: 11, type: 'entj', socType: 'LIE' }
    { id: 12, type: 'isfj', socType: 'ESI' }
    { id: 13, type: 'estj', socType: 'LSE' }
    { id: 14, type: 'infj', socType: 'FII' }
    { id: 15, type: 'enfp', socType: 'NEE' }
    { id: 16, type: 'istp', socType: 'SLI' }
  ]

`export default Personality`

templates/personalities.emblem

= each item in model
  = item.id
  = item.type
  = item.socType
  = item.description

Solution

  • Personality = DS.Model.extend
      id:           attr('number')
      type:         attr('string')
      socType:      attr('string')
    

    should be

    Personality = DS.Model.extend
      id:           DS.attr('number')
      type:         DS.attr('string')
      socType:      DS.attr('string')