ActiveRecord associations to the rescue!
If you add the following association to your model, all slugs that have ever been associated with it will be released when the model is destroyed (remember that this will not work if delete
is used instead of destroy
).
has_many :slugs, class_name: "FriendlyId::Slug", as: :sluggable, dependent: :destroy