Question

Does anyone know of a gem that both soft deletes records from a database (just flags them as deleted as opposed to is actually deleted) and...

...also when do you any type of find automatically omits those trashed records without using any special user-defined scopes. E.g. it all takes place in the gem.

Cheers!

Was it helpful?

Solution

You might want to checkout paper_trail

https://github.com/airblade/paper_trail

OTHER TIPS

DHH is a fan of doing this with 'concerns' which are basically just module mixins and I like that minimalist approach.

Here's DHH's version - https://gist.github.com/1014971

Here's my bugfixed version - https://gist.github.com/4032984

paper_trail has lots of features and is well tested (been around for a long time).

If you want just the specified functionality, check out:

https://github.com/grosser/soft_deletion

Paranoia

The Paranoia gem from the overtly talented Radar is what you'd be looking for.

It's essentially a rewrite of acts_as_paranoid (and uses many of the same conventions) but is smaller, faster and compatible with Rails 3 and 4.

It accomplishes both of your requests:

  1. Automatically sets a deleted_at timestamp when a destroy method is called on an object whose class includes acts_as_paranoid.

  2. Automatically sets a condition on any queries that ensure deleted_at IS NULL, unless you include with_deleted in your query chain.

Couldn't say enough good things about the library or Radar.

Bonus: His documentation might be the best in the "business".

I use Discard gem. It's a quite simple way for soft deletion records. https://www.rubydoc.info/gems/discard/1.0.0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top