meteorBuzz
meteorBuzz

Reputation: 3200

What is wrong with my subscription method on my route?

Can someone see why the route is not subscribing to the publication. Profiles = new Meteor.Collection('profiles');

The mongo database does have documents in this collection, but the browser console still has a count of 0 in Profiles collection.

I am trying to tell the router, "subscribe to user-profile publication, when you are ready, render the 'profile' template. I also named the route 'profile.'

Now I have noticed that after typingsub = Meteor.subscribe('user-profile'); and then sub.ready(); I get the count of the collection. Otherwise the path is not subscribed. This behaviour has not occurred before.

lib/router.js

Router.plugin('loading', {loadingTemplate: 'Loading'});

Router.route('user/profile', {
name: 'profile',
waitOn: function () {
 // return one handle, a function, or an array
 return Meteor.subscribe('user-profile');
 },

action: function () {
 // this.ready() is true if all items returned from waitOn are ready
 if (this.ready())
 this.render('profile');
 else
 this.render('Loading');
}
});

server.js:

Meteor.publish('user-profile', function () { 
return Profiles.find({userId: this.userId});
});

userId is a field in the Profiles collection. This profiles doc id is stored within the user.profile.experiences array for reference.

Upvotes: 0

Views: 71

Answers (1)

richsilv
richsilv

Reputation: 8013

Meteor.userId is a function which returns the _id, not the _id itself, and you can't pass a function over DDP anyway. It should be:

waitOn: function () {
  return Meteor.subscribe('user-profile', Meteor.userId());
}

Upvotes: 1

Related Questions