出于某种原因,我的应用程序现在莫名其妙地停止了托管版本(Galaxy& MLab)的工作。我可以在本地主机上运行时保存和检索帖子,但在我托管的版本上,它完全停止工作,现在我收到了此前我从未收到过的错误:
"模板帮助器中的异常:ReferenceError:未定义帖子"
我看到了使用" = new Mongo.Collection(' posts')"创建集合的新方法。但这似乎没有任何区别。
这个错误似乎发生在检索帖子并使用Posts.find()的所有4个帮助函数中,这里是其中一个函数(userfilteredposts):
Template.userPostsFiltered.helpers({
userfilteredposts: function() {
var currentUser = Meteor.userId();
var selectedListId = Session.get('selectedHood');
if (selectedListId == 0) {
return Posts.find({userId: currentUser}, {sort: {submitted:-1}},{reactive:true});
} else {
return Posts.find({userId: currentUser,neighborhood:selectedListId}, {sort: {submitted: -1}},{reactive:true});
}
}
});
以下是创建集合的方式:
Posts = new Meteor.Collection('posts');
Posts.allow({
'insert': function(userId, doc) {
return (userId && doc.user_id === userId)
},
'update': function(userId, docs, fields, modifier) {
for(var i=0; i<docs.length; i++ ){
if ( docs[i].user_id != userId) {
return false;
}
}
return true;
},
'remove': function(userId, docs) {
for(var i=0; i<docs.length; i++ ){
if ( docs[i].user_id != userId) {
return false;
}
}
return true;
}
});
Meteor.methods({
post: function(postAttributes) {
var user = Meteor.user(),
postWithSameLink = Posts.findOne({url: postAttributes.url});
// ensure the user is logged in
if (!user)
throw new Meteor.Error(401, "You need to login to post new places");
// ensure the post has a title
if (!postAttributes.name)
throw new Meteor.Error(422, 'Please fill in a name');
// pick out the whitelisted keys
var post = _.extend(_.pick(postAttributes, 'name','comment','address','location','neighborhood','map','placepic'), {
userId: user._id,
author: user.username,
submitted: new Date().getTime()
});
var postId = Posts.insert(post);
return postId;
}
});