Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

README

  • Loading branch information...
commit 00400aab3ea3b0441b2df62ed4336fa84068a2c6 1 parent 98e2d4f
@winton authored
Showing with 58 additions and 13 deletions.
  1. +58 −13 README.markdown
View
71 README.markdown
@@ -1,23 +1,68 @@
-GemTemplate
-===========
+ActsAsArchive
+=============
-A gem template for new projects.
+Don't delete your records, move them to a different table.
+Like <code>acts\_as\_paranoid</code>, but doesn't change all your SQL queries.
-Setup
------
+Install
+-------
+
+script/plugin:
+
+<pre>
+script/plugin install git://github.com/winton/acts_as_archive.git
+</pre>
+
+rubygems:
<pre>
-git clone git://github.com/winton/acts_as_archive.git my_project
-cd my_project
-rm -Rf .git
-git init
-git remote add origin git@github.com:winton/my_project.git
+# terminal
+sudo gem install winton-acts_as_archive
+
+# environment.rb
+config.gem "winton-acts_as_archive"
</pre>
-Rename these files/folders:
+Models
+------
+
+Add <code>acts\_as\_archive</code> to your models:
<pre>
-ls **/acts_as_archive*
+class Article < ActiveRecord::Base
+ acts_as_archive
+end
</pre>
-Do a project-wide find/replace on <code>acts_as_archive</code>.
+That's it!
+----------
+
+Next time your Rails instance boots up, the plugin replicates your table's structure into
+<code>archived\_articles</code> (as per the example), with an additional <code>deleted\_at</code> column.
+
+Use <code>destroy</code>, <code>delete</code>, and <code>delete_all</code> like you normally would.
+Records are copied into the archive table before being destroyed.
+
+Archive Model
+-------------
+
+Run finds on the archive by adding <code>::Archive</code> to your model:
+
+<pre>
+Article::Archive.find(:first)
+</pre>
+
+Restore
+-------
+
+Use <code>restore\_all</code> to copy archive records back to your table:
+
+<code>
+Article.restore_all([ 'id = ?', 1 ])
+</code>
+
+Auto-migrate from acts\_as\_paranoid
+------------------------------------
+
+If a <code>deleted\_at</code> column is present in your table, the plugin will attempt to move deleted
+records to the archive table.
Please sign in to comment.
Something went wrong with that request. Please try again.