Wednesday, September 30, 2009

How to Install and Use is_paranoid Gem in Rails 2.3+

Richard mentioned that in Rails 2.3, instead of acts_as_paranoid, you should use is_paranoid, per http://github.com/jchupp/is_paranoid. Thanks to Richard for providing the gem list -r and name of the gem and link.

For those interested, here is how to install it and use it.

Adding github gem repo (just in case you don't have it):

gem sources -a http://gems.github.com

Optional: finding related gems in remote repo:

gem list -r '.*is_paranoid.*'

Install the is_paranoid gem:

gem install jchupp-is_paranoid

Freeze the gem:

rake gems:unpack GEM=jchupp-is_paranoid

Add to config/environment.rb:

  config.gem "jchupp-is_paranoid", :lib => 'is_paranoid', :version => "= 0.8.2"

Add to app/model/NameOfMyModel within the class (replace NameOfMyModel and similar with your model name here and below!):

  is_paranoid

Create a migration via command-line:

script/generate migration add_deleted_at_to_name_of_my_model
Make db/migrate/..._add_deleted_at_to_name_of_my_model look like:
class AddDeletedAtToNameOfMyModel < ActiveRecord::Migration
  def self.up
    add_column :name_of_my_model, :deleted_at, :datetime
  end

  def self.down
    remove_column :name_of_my_model, :deleted_at
  end
end

No comments: