Last active
August 29, 2015 14:13
-
-
Save tsega/1251316397d9b143bd4b to your computer and use it in GitHub Desktop.
Meteor Sessions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Router.onBeforeAction(function(){ | |
var postSlug = this.params.slug; | |
var currentPost = Posts.findOne({slug: postSlug}); | |
var anonymousSession = "anonymousViewers_"+currentPost._id; | |
var anonymousCount = Session.get(anonymousSession); | |
if(anonymousCount){ | |
Session.set(anonymousSession, parseInt(anonymousCount) + 1); | |
}else{ | |
Session.set(anonymousSession, 1); | |
} | |
this.next(); | |
}, { | |
only: ["post"] | |
}); |
Router.onBeforeAction(function(){
var postSlug = this.params.slug;
var currentPost = Posts.findOne({slug: postSlug});
var anonymousSession = "anonymousViewers_"+currentPost._id;
var anonymousCount = Session.keys[anonymousSession]; // ** change here
var sessionObject = {};
if(anonymousCount){
sessionObject[anonymousSession] = parseInt(anonymousCount) + 1
}else{
sessionObject[anonymousSession] = parseInt(anonymousCount) + 1
}
Session.set(sessionObject);
this.next();
}, {
only: ["post"]
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I add the lines
8-12
my application just hangs. I just can't understand what I'm doing wrong.