Don't delete your records, move them to a different table.
acts_as_paranoid, but doesn't mess with your SQL queries.
sudo gem install acts_as_archive
acts_as_archive to your models:
Add this line to a migration:ActsAsArchive.update Article, Comment
Article, Commentwith your own models that use
Archive tables mirror your table's structure, but with an additional
There is an alternate way to create archive tables if you don't like migrations.
delete_alllike you normally would.
Records move into the archive table instead of being destroyed.
New migrations are automatically applied to the archive table.
No action is necessary on your part.
::Archiveto your ActiveRecord class:Article::Archive.find(:first)
restore_allto copy archived records back to your table:Article.restore_all([ 'id = ?', 1 ])
If you previously used
ActsAsArchive.updatecall will automatically move your deleted records to the archive table (see Create archive tables).
deleted_atvalues are preserved.
To keep insertions fast, there are no indexes on your archive table by default.
If you are querying your archive a lot, you will want to add indexes:class Article [ :id, :created_at, :deleted_at ] end
ActsAsArchive.updateupon adding new indexes (see Create archive tables).