Tengo esta aplicación hecha en nodejs. Necesito agregar el método put pero no me deja y no se donde está el error
- Aqui el código del ruter:
router.get("/post/:title", function(req, res){
var query = {"title" : req.params.title};
post.findOne(query, function(err, posts){
res.render("admin/posts/posts", {posts : posts});
});
});
router.put('/post/:title', function(req, res) {
var query = {"title": req.params.title};
var update = {title: req.body.title, body : req.body.post, created_at : req.body.date, autor: req.body.autor};
var options = {new: true};
post.findOneAndUpdate(query, update, options, function(err, posts){
console.log(posts)
res.render(
'admin/posts/post',
{title : 'posts - ' + posts.pregunta, posts : posts}
);
});
});
router.delete('/post/:title', function(req, res) {
var query = {"title": req.params.title};
post.findOneAndRemove(query, function(err, posts){
console.log(posts)
res.redirect('/admin/posts/');
});
});
2.codigo de la vista hbs
<form method="post" action="/admin/post/{{posts.title}}?_method=PUT">
titulo
<input type="text" name="title" value="{{posts.title}}">
entrada
<input type="text" name="body" value="{{posts.post}}">
fecha
<input type="date" name="date" value="{{posts.created_at}}">
autor
<input type="text" name="autor" value="{{posts.autor}}">
<button type="submit">Enviar</button>
</form>
<form method="post" action="/admin/post/{{posts.title}}?_method=DELETE">
<button type="submit">Delete</button>
</form>