Fabio Bracht
Fabio Bracht

Reputation: 423

Meteor.js error in loading Templates

Everything was working fine on my app (including the loadingTemplate, which was only being routed when actually required) until I decided to make a simple list on my home template to show every document on a Mongo collection called Rooms, by its title.

WHAT I'VE DONE

HTML:

<template name="roomsList">
  <div>
    {{#each rooms}}
      {{> roomsListItem}}
    {{/each}}
  </div>
</template>

<template name="roomsListItem">
    <ul>
        <li>{{title}}</li>
    </ul>
</template>

JS:

Template.roomsList.helpers({
    rooms: function() {
        return Rooms.find();
    }
});

As you can see, very basic stuff. The JS is just supposed to return all the documents on the Rooms collection (there are not many) so that the {{#each}} code block can iterate on them and catch all the titles to make the <ul>. I'm adding {{> roomsList}} on the home template.

PACKAGES I'M USING

I've seen this mentioned in other #meteor questions, so I'll go ahead and list here:

  1. accounts-password 1.0.4 Password support for accounts
  2. accounts-ui 1.1.3 Simple templates to add login widgets to an app
  3. iron:router 1.0.1 Routing specifically designed for Meteor
  4. meteor-platform 1.2.0 Include a standard set of Meteor packages in your app
  5. sacha:spin 2.0.4 Simple spinner package for Meteor

WHAT'S HAPPENING

Well, first, here's the bash error message:

I20141118-05:25:21.855(-2)? Exception from sub k7PEn4QcT9McjF8tw ReferenceError: rooms is not defined
I20141118-05:25:21.856(-2)?     at null._handler (app/server/publications.js:2:9)
I20141118-05:25:21.856(-2)?     at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1599)
I20141118-05:25:21.856(-2)?     at _.extend._runHandler (packages/ddp/livedata_server.js:943)
I20141118-05:25:21.857(-2)?     at _.extend._startSubscription (packages/ddp/livedata_server.js:769)
I20141118-05:25:21.857(-2)?     at _.extend.protocol_handlers.sub (packages/ddp/livedata_server.js:582)
I20141118-05:25:21.860(-2)?     at packages/ddp/livedata_server.js:546

I suspect the first line is causing all the others, but I can't work out what it's telling me. I am calling the collection in other parts of the app, in the same manner, without a problem. So I have no idea what's causing the problem here!

Secondly, now my home template won't load. All that's loading is the loading template, which is declared on the Router.settings. It loads for every URL, and never redirects to anything. I tried being logged in and logged off.

Finally, the list doesn't even work, because I've put the {{>roomsList}} on the loading template just to see if was working and it wasn't.

How can i fix this?

UPDATE: I was requested in the comments to share the code for subscription and publishing, as there may be some typos. I don't think there are, because I was accessing the collection in another part of the code without problems, but here they are:

Publication (on /server):

Meteor.publish("rooms", function() {
    return rooms.find();
});

Subscription (on /lib):

Router.configure({
    layoutTemplate: "layout",
    loadingTemplate: "loading",
    notFoundTemplate: "notFound",
    waitOn: function() { return Meteor.subscribe('rooms'); }
});

Upvotes: 1

Views: 345

Answers (1)

SG_
SG_

Reputation: 1336

In your publishing code you have to use Rooms instead of rooms, That is your collection name. Like this

 Meteor.publish("rooms", function() {
   return Rooms.find();
});

Upvotes: 1

Related Questions