I have received the following error when trying to delete a value in rails "cannot delete or update a parent row a foreign key constraint fails rails"
This is perfectly acceptable to me as I don't want the user to be able to delete the value if it's associated with another value. However, what is the best way to catch the exception and then notify 'alert' the user that this value cannot be deleted?
Thank You,
TW
There are plenty of ways to handle this gracefully. If you'd like to do a check before the destroy I recommend you take a look at this post as it shows a good example of using the before_destroy
method and gives you control of the error you show. However, you can also add a rescue_from
and capture the error in your controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With