An ActiveRecord Plugin to Prevent Destroy if Associations Are Present

I’ve just released a small plugin that adds ActiveRecord models a way to prevent destroy if specified has_many, has_one and/or 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.