Jadam
Jadam

Reputation: 1787

Ember: Error while processing route: not defined

Not seeing what I'm missing to cause 'Posts' template to be rendered blank in the browser. My other templates are rendering as normal.

I'm getting the error:

Error while processing route: posts posts is not defined ReferenceError: posts is not defined

My route file:

Blogger.PostsRoute = Ember.Route.extend({
  model: function() {
    return posts;
  }
});

View:

  <ul>
    {{#each}}
      <li>{{title}}</li>
    {{/each}}
  </ul>

Index calling the store.js file with the posts, my router, and 'posts' in the template loader:

  <script src="blogger.js"></script>
  <script src="router.js"></script>
  <script scr="store.js"></script>

  <script src="controllers/about.js"></script>
  <script src="controllers/contact.js"></script>

  <script src="routes/posts.js"></script>

  <script>
    EmberHandlebarsLoader.loadTemplates([ 
      'posts', 'about', 'contact', 'phone', 'email', 'application'
    ]);
</script>

In my store.js file:

var posts = [
  {
    id: '1',
    title: "title text",
    body: "body text"
  },
  {
    id: '2',
    title: 'title text two',
    body: "lorem ipsum"
  }
];

JSfiddle: http://jsfiddle.net/t6ndtbLq/2/

Upvotes: 0

Views: 1864

Answers (2)

michael
michael

Reputation: 2997

Since the error that posts is not defined, and in your store.js file it clearly says var posts = ..., the first thing to check is that store.js is being loaded properly. Your script tag says <script scr="store.js"></script> - if you fix your typo from scr... to src, it should work.

Upvotes: 1

Trek Glowacki
Trek Glowacki

Reputation: 3621

Just from the code in this sample, the variable posts in

model: function() {
  return posts;
}

is never defined. Which is why the browser is telling you ReferenceError: posts is not defined

Upvotes: 1

Related Questions