Installed the acts_as_paranoid plugin today for a top secret project I am working on. The documentation is quite lacking so I’ll fill in a few holes here. This may be obvious to everyone else out there but in order for it to work you need to add the following to the end of your environment.rb file:

require_gem 'acts_as_paranoid'

Doing this got rid of the 500 error I was encountering, but my objects were still being outright deleted, instead of having the deleted_at field set. A checked of the development.log showed that tasks.deleted_at IS NULL was being injected into SQL queries. So obviously the plugin was working on some level. My class looked like the following:

class Task
  acts_as_taggable
  <strong>acts_as_paranoid</strong>

For grins I tried swapping those two acts_* statements:

class Task
  <strong>acts_as_paranoid</strong>
  acts_as_taggable

And it started working correctly! Not sure the cause of this I’ll try and ping the developers for acts_as_paranoid.

Also, while for the most part I wanted deleted items to not show up in any associations there were a few where I still wanted the deleted association to be retrieved. I solved this by adding the following:

class TimeEntry < ActiveRecord::Base
  belongs_to :task

  def task
    <strong>Task.find_with_deleted(task_id) if task_id != 0</strong>
  end

If you know of a more elegant way to do this, drop me a line and let me know.

2 Comments

  1. Hi, i would like to add the following that the existing version doesn’t work with Rails 1.1, due to the assumption on the part that scoped_methods is not an array (scope up to one level onf nesting only). With the added support to nested scope in Rails 1.1, the part of the code where it tries to work around the scope method no longer works.

    I’ve created a simple work-around to this problem, and i’ve outlined it on my website. I thought you might be interested to take a look:

    http://cebu.palmade.net/blog/ruby-on-rails/acts_as_paranoid-fix-for-rails-11-and-beyond/

  2. Mark: Interesting, I had actually just dropped my usage of the plugin a few days ago when I found that it didn’t work for Rails 1.1. I don’t really need its functionality currently so I just dropped it without much research, but I’ll look into your workaround. Have you passed your work along to the developers of acts_as_paranoid?