I have a Crud NodeJs where I can add data to the database, but now I wanted to edit this data and the tutorial I follow is a bit old, in this tutorial editing is done by PUT
my JADE page looks like this:
extends ../layout
block content
h1 Alteração de Usuário
hr
br
form(method="POST", action="/usuarios/edit/#{value._id}", role="form")
input(type="hidden" name="_method" value="put")
div(class="form-group")
label Nome:
input(type="text", name="nome", class="form-control", value="#{value.nome}")
div(class="form-group")
label Login:
input(type="text", name="login", class="form-control", value="#{value.login}")
input(type="submit", value="Atualizar", class="btn btn-success")
br
br
a(href="/usuarios" title="Voltar") Voltar
And this is my update method that stays in control:
update: function(req,res){
Usuario.findById(req.params.id, function(err, data){
if(err){
console.log(err);
}else{
var model = data;
model.nome = req.body.nome;
model.login = req.body.login;
model.save(function(err){
if(err){
console.log(err);
}else{
res.redirect('/usuarios');
}
});
}
});
}
And the route is this:
app.put('/usuarios/edit/:id', usuarios.update);
Can anyone help?