Skip to content

Instantly share code, notes, and snippets.

@xsyn
Created May 26, 2011 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xsyn/992780 to your computer and use it in GitHub Desktop.
Save xsyn/992780 to your computer and use it in GitHub Desktop.
Callback with res
== model/dreamModel.js
DreamModel.prototype.save = function(articles, callback) {
if( typeof(articles.length) == 'undefined') {
articles = [articles];
}
for(var i=0;i<articles.length;i++) {
article = articles[i];
articles.created = new Date();
}
this.db.save(articles, function(err, res) {
if(err) {
console.log(err)
callback(err)
} else {
callback(null, res);
}
});
};
== Node app.js
app.post('/dreams/dreams', function(req, res) {
var document = new DreamModel(req.body['dream']);
document.save(req.body['dream'], function(req, res) {
res.redirect('/dreams');
});
});
== Error
/Users/xsyn/Development/didit.co.za/pages.js:65
res.redirect('/dreams');
TypeError: Object [{"id":"f3ea24911c5bfcce15cfb25160005d31","rev":"1-7591d82bf8117e46ab1ac6320521ee89"}] has no method 'redirect'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment