Sean L
Sean L

Reputation: 827

Meteor this.params._id is undefined based upon ":_id?"

I have a game that I know works properly with an ID per the code on the client side. For example if I were to use the below with {{game._id}} it works properly:

Template.gamePage.game = function() {
    return GameCollection.findOne({current: true});
}; 

However, I am trying to gain access to the publications of 'submissions; only for the specific game ID. Console log below returns undefined.

router.js

this.route('gamePage', {
     path: '/games/:_id?',
     waitOn: function() {
         console.log(this.params._id);
         return [
             Meteor.subscribe('randomQuestions', Random.id()),
             Meteor.subscribe('submissions', this.params._id)
             ];
     }
    });

I suspect that params._id pulls from games/:_id, however, I would like it so that that it remains games/:_id? so that I do not have an unnecessary long address.

Any thoughts on why I am getting undefined for params._id

Upvotes: 0

Views: 583

Answers (1)

Walter Zalazar
Walter Zalazar

Reputation: 541

I think you have one button for to access a game, for example...

Tracker.autorun(function () {
  Session.set('gameCurrent');
});

Template.gamePage.helpers({
   allGames: function(){
     return GameCollection.find({});
   },
   getCurrentGame:function(){
     return Session.get('gameCurrent');
   }

})

// with this action you access a the route with the id specified
Template.gamePage.events({
 'click button#game' : function(event,template){
    Session.set('gameCurrent',this._id);
    Router.go('editEmail',{_id:this._id})
  }
})

Remember that Session only works in the client.

Upvotes: 0

Related Questions