0
next:
I literally started working with Nodejs + Express + Mongodb today and as an exercise I started with the famous CRUD (Create, Read, Update, Delete).
I managed to do almost everything except the editing part, I’m really "beating myself" to solve, a long time ago and 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 don’t know almost anything about this syntax, which is new to me, follows below the html form (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 ejs template.
I appreciate anyone who can help me!
as you have
router.put('/edit', ...
, shouldn’t be<form action="/edit" method="put">
?– mercador
CRUD means: Create, Read, Update, Delete
– Sergio
@merchant already tried but does not change anything, it is as if he did not find what I am doing in the code of Edit because it takes me to a page of error 404.
– Guilherme Leonardo Utzig