before_destroy callback not stopping record from being deleted
In Rails 5 you have to throw :abort otherwise it won’t work. (even returning false) Also, you should add prepend: true to the callback, to make sure it runs before the dependent: :destroy on the parent models. Something like this should work: class Something < ApplicationRecord before_destroy :can_destroy?, prepend: true private def can_destroy? if model.something? … Read more