From e75c3000251a8ac2f0946992342c56537619952f Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Tue, 22 Nov 2016 23:07:08 +0100 Subject: [PATCH] remove article from author --- controllers/authors.js | 9 +++++++++ views/authors/edit.ejs | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/controllers/authors.js b/controllers/authors.js index 6e9c51d..561d763 100644 --- a/controllers/authors.js +++ b/controllers/authors.js @@ -63,4 +63,13 @@ router.post('/:id/articles', function(req, res){ }); }); +router.delete('/:authorId/articles/:articleId', function(req, res){ + Author.findById(req.params.authorId, function(err, foundAuthor){ + foundAuthor.articles.id(req.params.articleId).remove(); + foundAuthor.save(function(){ + res.redirect('/authors/' + req.params.authorId + '/edit'); + }) + }); +}); + module.exports = router; diff --git a/views/authors/edit.ejs b/views/authors/edit.ejs index 4cecb10..f8e48b3 100644 --- a/views/authors/edit.ejs +++ b/views/authors/edit.ejs @@ -30,7 +30,12 @@

Articles Written By This Author