|
|
|
@ -12,13 +12,22 @@ router.get('/', function(req, res){
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
router.get('/new', function(req, res){
|
|
|
|
router.get('/new', function(req, res){
|
|
|
|
res.render('articles/new.ejs');
|
|
|
|
Author.find({}, function(err, allAuthors){
|
|
|
|
|
|
|
|
res.render('articles/new.ejs', {
|
|
|
|
|
|
|
|
authors:allAuthors
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
router.post('/', function(req, res){
|
|
|
|
router.post('/', function(req, res){
|
|
|
|
Article.create(req.body, function(err, createdArticle){
|
|
|
|
Author.findById(req.body.authorId, function(err, foundAuthor){
|
|
|
|
res.redirect('/articles');
|
|
|
|
Article.create(req.body, function(err, createdArticle){
|
|
|
|
})
|
|
|
|
foundAuthor.articles.push(createdArticle);
|
|
|
|
|
|
|
|
foundAuthor.save(function(){
|
|
|
|
|
|
|
|
res.redirect('/articles');
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
router.get('/:id', function(req,res){
|
|
|
|
router.get('/:id', function(req,res){
|
|
|
|
|