Don't delete your records, move them to a different table.
acts_as_paranoid, but doesn't change all your SQL queries.
script/plugin install git://github.com/winton/acts_as_archive.git
# terminal sudo gem install winton-acts_as_archive # environment.rb config.gem "winton-acts_as_archive", :lib => "acts_as_archive", :source => "http://gems.github.com"
acts_as_archive to your models:
class Article < ActiveRecord::Base acts_as_archive # Or you can add custom archive table indexes acts_as_archive :indexes => [ :id, :deleted_at ] end
cd your_rails_app acts_as_archive
This command replicates your table's structure into
(as per the example), with an additional
Run again if you add more
delete_all like you normally would.
Records are copied into the archive table before being destroyed.
What if my schema changes?
Any new migrations on your
acts_as_archive table are automatically applied to the archive table.
Query the archive
::Archive to your ActiveRecord class:
Restore from the archive
restore_all to copy archived records back to your table:
Article.restore_all([ 'id = ?', 1 ])
Auto-migrate from acts_as_paranoid
deleted_at column is present in your table, the plugin will attempt to move deleted
records to the archive table. The
deleted_at value is preserved.