gist: 1149020, 2011-08-16 13:02:37Z
// create new post
app.post("/blog", function _create(req, res) {
var post = {
"content": req.body.content,
"title": req.body.title,
"datetime": Date.now(),
"type": "post"
}
model.get(function _get(err, rows) {
// get highest id and make the new id one higher.
var id = rows.map(function _pluckId(v) {
return v.value.id;
}).reduce(function _findMaxId(prev, curr) {
return prev < curr ? curr : prev;
}, 0);
post.id = ++id;
model.create(post, function _save() {
res.redirect("blog/" + view.url(post));
});
});
});