An ActiveRecord Plugin to Prevent Destroy if Associations Are PresentSun, Aug 7, 2011
I’ve just released a small plugin that adds ActiveRecord models a way to prevent destroy if specified
belongs_to associations are present. This is achieved by adding a before_destroy callback that aborts the destroy and adds a base error on the instance when detecting associations.
It’s inspired from this stackoverflow answer and was created to factorize this solution when you need it for various models in an application.