Answer the question
In order to leave comments, you need to log in
Why doesn't code work on meteor.js without checking with the check package?
There is the following code in Meteor.js - the postInsert method is called on the submit event
Template.postSubmit.events({
'submit form': function(e) {
e.preventDefault();
var post = {
url: $(e.target).find('[name=url]').val(),
title: $(e.target).find('[name=title]').val()
};
Meteor.call('postInsert', post, function(error, result) {
// отобразить ошибку пользователю и прерваться
if (error)
return alert(error.reason);
Router.go('postPage', {_id: result._id});
});
}
});
Meteor.methods({
postInsert: function(postAttributes) {
check(Meteor.userId(), String);
check(postAttributes, {
title: String,
url: String
});
var user = Meteor.user();
var post = _.extend(postAttributes, {
userId: user._id,
author: user.username,
submitted: new Date()
});
var postId = Posts.insert(post);
return {
_id: postId
};
}
});
/*check(Meteor.userId(), String);
check(postAttributes, {
title: String,
url: String
});*/
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question