Following:
I started literally today working with NodeJS + Express + MongoDB and as an exercise I started with the famous CRUD (Create, Read, Update, Delete).
I was able to do almost anything but edit, I'm really "beating myself" to solve, a good time and I decided to ask for help.
Editing code
// Editar item
router.put('/edit', function(req, res) {
var id = req.body.id;
var title = req.body.title;
var description = req.body.description;
model.findById(id, function(error, task) {
if (error) {
throw error;
}
task.title = title;
task.description = description;
task.save(function() {
res.redirect('/');
});
});
});
I'm really having trouble finding the error since I do not handle almost any of this syntax, which is new to me, below the form in html (ejs)
<form action="/add" method="post">
<legend>Incluir uma tarefa</legend>
<input type="text" name="title" placeholder="Título">
<textarea name="description" placeholder="Descrição"></textarea>
<button type="submit">Adicionar</button>
</form>
I'm using the template ejs.
Thank you for helping me!