New to Rails 3? Check out the Ruby on Rails 3 Tutorial book and screencast.

A book and screencast series showing you how to develop and deploy industrial-strength Rails apps in a direct, step by step way. The screencast series includes 12 lessons over more than 15 hours! Get the best "over the shoulder" experience of following what a top Rails 3 developer does when building an app today. Click here to learn more.

Re-implementing acts_as_paranoid using default_scope in Rails 2.3

In Elsewhere, Plugins, Tips

A few months ago Mike Gunderloy wrote 3 Plugins for Safer ActiveRecord Deletions for Rails Inside and mentioned acts_as_paranoid, a plugin that flags ActiveRecord objects as deleted without actually deleting them (this is useful if you might need to "undo" the delete later).

Now, Jeff Chupp has used Rails / ActiveRecord 2.3's default_scope feature to implement a similar feature to acts_as_paranoid in just a few lines of regular model code. He's also wrapped this up into a plugin of his own called is_paranoid.

david-berube.jpgSupport from: David Berube. Is your Rails app running slow? I'm David Berube, author of Practical Reporting with Ruby and Rails, and I can help. Call me at (603)-485-9622 for a free consultation and $100 off your first project.

Post to Twitter Tweet This Post

Vaguely Related Posts (Usually)

3 Comment Responses to “Re-implementing acts_as_paranoid using default_scope in Rails 2.3”

  1. #1
    Hubert Łępicki Says:

    I think both solutions - named scope and acts_as_paranoid are implemented in wrong layer. It should be handled by database, making copies, or preserving delted records with some sort of versioning. Not sure if there are any solutions out there for MySQL but I am pretty sure you can do it in Postgres or Oracle.

  2. #2
    Geoffrey Grosenbach Says:

    Apparently it's dead already:

    http://blog.semanticart.com/killing_is_paranoid/

  3. #3
    Lee Smith Says:

    I was disappointed in hearing that is_paranoid was getting abandoned...I was literally a day away from implementing it in a project.

Leave a Reply