From 3126a68d18080dbb7ec5c8b956402d28a4830066 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Fri, 25 Nov 2016 03:52:24 +0100 Subject: [PATCH] show author in article show page --- controllers/articles.js | 7 +++++-- views/articles/show.ejs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/controllers/articles.js b/controllers/articles.js index 54bde25..0985eec 100644 --- a/controllers/articles.js +++ b/controllers/articles.js @@ -32,8 +32,11 @@ router.post('/', function(req, res){ router.get('/:id', function(req,res){ Article.findById(req.params.id, function(err, foundArticle){ - res.render('articles/show.ejs', { - article: foundArticle + Author.findOne({'articles._id':req.params.id}, function(err, foundAuthor){ + res.render('articles/show.ejs', { + author: foundAuthor, + article: foundArticle + }); }); }); }); diff --git a/views/articles/show.ejs b/views/articles/show.ejs index 997527e..88e5e4a 100644 --- a/views/articles/show.ejs +++ b/views/articles/show.ejs @@ -6,7 +6,7 @@
-

<%=article.title%>

+

<%=article.title%> by <%=author.name%>