Created
April 19, 2011 18:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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