Is there a more efficient version of something like act_as_paranoid for Rails 3?

Does anyone know about a gem that also gently deletes records from the database (just puts them as deleted rather than actually deleted) and ...

... also when you any type of search automatically omit these trimmed entries without using any special user areas. For instance. it all happens in a gem.

Hooray!

+4
source share
4 answers

You might want to check paper_trail

https://github.com/airblade/paper_trail

+3
source

DHH is a fan of this with "problems", which are basically just modular mixers, and I like this minimalist approach.

Here is the DHH version - https://gist.github.com/1014971

Here is my bug fix version - https://gist.github.com/4032984

+7
source

paper_trail has many functions and is well tested (it has been a long time).

If you want only the specified functions, check:

https://github.com/grosser/soft_deletion

+2
source

Paranoia

The paranoia gem from frankly talented Radar is what you were looking for.

This is essentially a rewriting of acts_as_paranoid (and uses many of the same conventions), but is smaller, faster, and compatible with Rails 3 and 4.

Fulfills both of your requests:

  • Automatically sets the deleted_at when calling the destroy method on an object whose class includes acts_as_paranoid .

  • Automatically sets the condition for any queries that provide deleted_at IS NULL unless you include with_deleted in the query chain.

Can't say enough good things about the library or the radar.

Bonus: its documentation may be the best in "business."

+2
source

All Articles