#The Delete button on index page (à la "jquery AJAX")
include jquery
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"> </script>
add button to loop. Notice id is set to Mongo ID
<li><div class="btn btn-danger glyphicon glyphicon-trash" id="<%= candies[i].id %>"></div></li>
Just a little bit of AJAX:
<script type="text/javascript">
$('.btn').click(callDelete)
function callDelete(){
console.log(this.id)
$.ajax({
url: '/candies/' + this.id,
type: 'DELETE',
success: function(result) {
//console.log(result)
//hack for forcing page reload
location.reload()
}
})
};
</script>