After spending the last 4 and a half hours scouring the internet, I'm still stuck on why my insert method in my real time messaging app isn't working. It's not throwing any errors, it's just not actually inserting anything.
Here's the code snippet for it: JS client:
Template.input.events({
"keypress .input": function(event, template){
if(event.which == 13){
event.preventDefault();
var user = Meteor.user();
var message = template.find(".input").value;
alert(Meteor.call("insert", user.username, message));
template.find(".input").value = "";
}
}
});
JS Server:
Meteor.methods({
'insert':function(username, message){
Messages.insert({
'message': message,
'user': Meteor.userId(),
'username': username,
'timestamp': new Date()
});
return "success";
},
'find': function(){
Messages.find({}, {sort: {timestamp:-1}});
}
});
HTML:
<template name="input">
<div id="input">
<input class="input" type="text" placeholder="Message..." id="message" />
</div>
</template>
Even after checking the console, nothing seems to be getting added.