I'm using the paper_trail gem for a blogging system to store versions of the article. However I don't need to keep any version of an article after it has been destroyed.
How can I delete all versions of a model instance when it's destroyed? I only see in the documentation a way to delete versions globally.
Any ideas?
before_destroy do
self.versions.destroy_all
end
By default has_paper_trail
creates has_many :versions
association. So you can easily destroy all of them. But make sure in your model you have this :
has_paper_trail on: [:create, :update] #because you dont want to keep record for destroy event.
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