I am trying to add a profile page to the microscope app. Thanks to help I got here I was able to get most of it working but I can't get the route to another users profile to work. This is the code for the route. Thanks
in comment.html template
<span class="author"><a href="{{pathFor 'user_profile'}}">{{username}}</a></span>
router.js
this.route('user_profile',{
path: '/profile/:_username',
waitOn: function () {
return Meteor.subscribe('userprofile', this.params._username)
},
data: function () {return user.findOne(this.params._username)}
});
publications.js
Meteor.publish('userprofile', function (username) {
return user.find(username);
});
profile.js
Template.user_profile.helpers({
username: function() {
return this.user().username;
},
bio: function() {
return this.user().profile.bio;
}
});
The default Meteor user collection used by accounts-base and accounts-password is
Meteor.users
, notuser
. Also,collection.find(x)
will find a document whose_id
isx
; if you want to find documents whoseusername
isx
, you needcollection.find({username: x})
.I renamed the
_username
parameter tousername
, that way thepathFor
helper will be able to automatically fill it in. I also replaceduser
withMeteor.users
and passed in the correct selector.I replaced
user
withMeteor.users
and fixed the selector again, and I limited which fields we publish (since the user document contains sensitive data like login tokens, you don't want to publish the whole thing).Inside the
user_profile
template, the data context (which you specified in thedata
parameter in the route) is a user document, sothis
is already a user document. Note that these helpers are redundant (you can get the username with{{username}}
and the bio with{{profile.bio}}
even without these helpers).