diff --git a/controllers/articles.js b/controllers/articles.js index cb21be3..a4f0b2d 100644 --- a/controllers/articles.js +++ b/controllers/articles.js @@ -34,4 +34,19 @@ router.delete('/:id', function(req, res){ }); }); +router.get('/:id/edit', function(req, res){ + Article.findById(req.params.id, function(err, foundArticle){ + res.render('articles/edit.ejs', { + article: foundArticle + }); + }); +}); + +router.put('/:id', function(req, res){ + Article.findByIdAndUpdate(req.params.id, req.body, function(){ + res.redirect('/articles'); + }); +}); + + module.exports = router; diff --git a/views/articles/edit.ejs b/views/articles/edit.ejs new file mode 100644 index 0000000..e79fb5c --- /dev/null +++ b/views/articles/edit.ejs @@ -0,0 +1,32 @@ + + + + + + + +
+

Edit <%=article.title%>'s Info

+ +
+
+

Article Attributes:

+
+ + + +
+
+ + diff --git a/views/articles/show.ejs b/views/articles/show.ejs index 0c8d3f1..997527e 100644 --- a/views/articles/show.ejs +++ b/views/articles/show.ejs @@ -19,10 +19,17 @@
- <%=article.body%> -
- -
+
+ <%=article.body%> +
+
+ Edit +
+
+
+ +
+