I created an app that adds and removes 'Case Studies'. I am able to add entries easily, but when I try to delete an entry, I am redirected of the form page with the form action URL appended to the end. The entry does in fact get deleted when I go back to the original form page, but ideally I'd like to be able to stay on the same page as I add/delete entries.
form.jade
form(method="POST", action="/form/#{entry._id}?_method=DELETE")
input(type="submit", value="Delete")
form.js
/* Delete Case Study */
router.delete('/:id', function (req, res) {
Entry.findById(req.params.id)
.exec(function(err, entries) {
// changed `if (err || !doc)` to `if (err || !entries)`
if (err || !entries) {
res.statusCode = 404;
res.send({});
} else {
entries.remove(function(err) {
if (err) {
res.statusCode = 403;
res.send(err);
} else {
res.send('Deleted entry with link: ', entries.link);
}
});
}
});
});
Here is a link to my app on Heroku, as well as my GitHub repo:
https://hidden-wave-1121.herokuapp.com/form
https://github.com/hlmurray/express-app
Any help here would be great, thank you!