I am currently facing an issue where I am unable to delete a specific 'ticket' from the database. The webpage shows a table listing all the tickets with their respective seat names and prices, along with a delete button (form). However, when I try to delete a ticket using the delete button, it always deletes the first ticket in the list, no matter which one I select.
Below is the controller function:
Ticket.findOneAndDelete(req.params.id, function(err) {
console.log('The delete button works in the Tickets router')
res.redirect('/tickets');
});
};
Router:
router.post('/tickets/:id', ticketsCtrl.delete)
EJS snippet:
<tr>
<td><%= t.seat %></td>
<td><%= t.price %></td>
<td>
<form id="delete-ticket-form" method="POST"
action="/tickets/<%= t._id %>">
<input type="submit" value="X">
</td>
</tr>