Created
April 28, 2015 14:04
-
-
Save tiansial/42fd278c3a43c393ab19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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