Setting up acts_as_paranoid

July 28th, 2007

Due to a very small amount of documentation, and the loads of outdated documentation, on how to get started, I'm going writing a quick how to. It's very quick and easy; not much to it, just make sure you are working with the most up to date svn repository before you start. Follow the steps below.
  1. Navigate to your rails project folder and run the following command ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/acts_as_paranoid/
  2. Create a migration(s) for all your database tables that do not contain a deleted_at (datetime) column that you wish to use this with by running ruby script/generate migration add_deleted_at_column
  3. In the migration use the add_column :table_name, :column_name, :datetime syntax, and the opposite, remove_column for migrating backwards.
  4. Add acts_as_paranoid under the model name of all your models you wish to use this with.
  5. Test it out and you should be populating the field deleted_at now instead of deleting the entire row.
Acts_as_paranoid is a great way to keep data in your database for future reference and reporting; as well as a fail safe if anyone accidentally deletes things they should not. Additionally, :dependent => :destroy applied to your has_many association method works great with acts_as_paranoid as well since it overrides :destroy method with the deleted_at update.

Sorry, comments are closed for this article.