Skip to content

Instantly share code, notes, and snippets.

@tiansial
Created April 28, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiansial/42fd278c3a43c393ab19 to your computer and use it in GitHub Desktop.
Save tiansial/42fd278c3a43c393ab19 to your computer and use it in GitHub Desktop.
put(function(req, res) {
// Get our REST or form values. These rely on the "name" attributes
var email = req.body.email;
var password = req.body.password;
var servico = req.body.servico;
//find the document by ID
mongoose.model('Email').findById(req.id, function (err, email) {
//update it
email.update({
email : email,
password : password,
servico : servico
}, function (err, emailID) {
if (err) {
res.send("There was a problem updating the information to the database: " + err);
}
else {
//HTML responds by going back to the page or you can be fancy and create a new view that shows a success page.
res.format({
html: function(){
res.redirect("/emails");
},
//JSON responds showing the updated values
json: function(){
res.json(email);
}
});
}
})
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment