Tom chan
Tom chan

Reputation: 365

waitOn hook on Iron router for Subsciption: Images not loading

For my iron:router, I have a waitOn hook for subscription to a collection. Whenever I put the hook on, the page can't load the pictures from Public folder and I am not sure why that is.....

But whenever I remove the WaitOn hook, the picture loads again.

Subscription at Router

Router.route('/postPage/:_id', {
  name: 'profile',
  waitOn: function() {return Meteor.subscribe('comments', this.params._id) ;},
  data: function() { return Posts.findOne(this.params._id); }
});

Publication

Meteor.publish('comments', function(postId) {
  check(postId, String);
  return Comments.find({postId: postId});
});

Upvotes: 0

Views: 49

Answers (2)

erickeno
erickeno

Reputation: 188

try data: function() { return Posts.findOne(_id: this.params._id); }

Upvotes: 0

David Weldon
David Weldon

Reputation: 64332

One reason it could fail to load is that the waitOn is never returning. waitOn will block until all its subscriptions are all marked as ready by their respective publishers. In this case, the comments publisher would fail if postId isn't a string - an error will be thrown and this.ready() will never be called. I'd recommend debugging further by:

  1. ensuring this.params._id is actually a string
  2. temporarily removing check(postId, String) from the publisher

Upvotes: 1

Related Questions