Created
May 26, 2011 08:36
-
-
Save xsyn/992780 to your computer and use it in GitHub Desktop.
Callback with res
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
== 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