Skip to content

Instantly share code, notes, and snippets.

@robomatic
Created May 28, 2015 20:27
Show Gist options
  • Save robomatic/35d9520333dfabf75dbc to your computer and use it in GitHub Desktop.
Save robomatic/35d9520333dfabf75dbc to your computer and use it in GitHub Desktop.
meteor method call error
Comments = new Mongo.Collection('comments');
if (Meteor.isClient) {
Meteor.subscribe('allComments');
Meteor.call("callMe", "Rob", function(err, result) {
if (err) throw err;
console.log('result: ' + result);
});
Template.CommentList.helpers({
comments: function () {
return Comments.find();
},
formatTimestamp: function (timestamp) {
return moment(timestamp).fromNow();
}
});
Template.CommentAdd.events({
'submit form': function (e, tmpl) {
e.preventDefault();
var form = tmpl.find('form');
var commentEl = tmpl.find('[name=comment]');
var comment = commentEl.value;
Comments.insert({
login: 'cmather',
timestamp: new Date,
room: 'test',
comment: 'test comment'
})
}
})
}
if (Meteor.isServer) {
Meteor.methods({
callMe: function (name) {
return "hello, " + name;
}
});
Meteor.publish('allComments', function(){
var cursor = Comments.find();
var self = this;
var observeHandle = cursor.observeChanges({
added: function(id, fields) {
self.added('comments', id, fields)
},
changed: function (id, fields) {
self.changed('comments', id, fields)
},
removed: function (id) {
self.removed('comments', id)
}
});
this.ready();
this.onStop(function (){
observeHandle.stop();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment