Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created August 16, 2011 13:02
Show Gist options
  • Save Raynos/1149020 to your computer and use it in GitHub Desktop.
Save Raynos/1149020 to your computer and use it in GitHub Desktop.
// 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));
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment