Skip to content

Instantly share code, notes, and snippets.

@cowboycoded
Created April 19, 2011 18:54
Show Gist options
  • Save cowboycoded/929262 to your computer and use it in GitHub Desktop.
Save cowboycoded/929262 to your computer and use it in GitHub Desktop.
This rake task/monkeypatch creates the inital paper_trail version for existing records.
namespace :app_tasks do
desc "create initial paper_trail version for existing records"
task(:create_paper_trail_versions => :environment) do
#MONKEY PATCH
module PaperTrail
module Model
module InstanceMethods
def create_initial_pt_version
record_create if versions.blank?
puts "created #{self.class} #{self.id}"
end
end
end
end
#UPDATE RECORDS
ActiveRecord::Base.descendants.each do |model|
if model.methods.include?(:paper_trail_enabled_for_model)
model.all.each do |record|
record.create_initial_pt_version
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment