paranoia gem
# Step 1: Add the 'paranoia' gem to your Gemfile
# Gemfile
gem 'paranoia'
# Step 2: Install the gem using Bundler
$ bundle install
# Step 3: Add 'paranoia' to your ActiveRecord model
# app/models/your_model.rb
class YourModel < ActiveRecord::Base
acts_as_paranoid
end
# Step 4: Generate and run a migration to add the 'deleted_at' column
$ rails generate migration AddDeletedAtToYourModel deleted_at:datetime:index
$ rake db:migrate
# Step 5: Use soft delete methods in your application
# Example:
# Soft delete a record
record = YourModel.find(id)
record.destroy
# Recover a soft-deleted record
deleted_record = YourModel.only_deleted.find(id)
deleted_record.restore
# Permanently delete a record
deleted_record = YourModel.only_deleted.find(id)
deleted_record.really_destroy!
Note: Replace 'YourModel' with the actual name of your ActiveRecord model where you want to implement soft deletes.