Print any errors when saving the initial journal instead of aborting

This commit is contained in:
Eric Davis 2011-06-16 19:19:17 -07:00
parent 52b83da8dd
commit 8b13992c0a
1 changed files with 15 additions and 7 deletions

View File

@ -42,14 +42,22 @@ class BuildInitialJournalsForActsAsJournalized < ActiveRecord::Migration
elsif o.respond_to?(:user)
new_journal.user = o.user
end
new_journal.save
new_journal.reload
if new_journal.save
new_journal.reload
# Backdate journal
if o.respond_to?(:created_at)
new_journal.update_attribute(:created_at, o.created_at)
elsif o.respond_to?(:created_on)
new_journal.update_attribute(:created_at, o.created_on)
# Backdate journal
if o.respond_to?(:created_at)
new_journal.update_attribute(:created_at, o.created_at)
elsif o.respond_to?(:created_on)
new_journal.update_attribute(:created_at, o.created_on)
end
else
if new_journal.errors.count == 1 && new_journal.errors.first[0] == "version"
# Skip, only error was from creating the initial journal for a record that already had one.
else
puts "ERROR: errors creating the initial journal for #{o.class.to_s}##{o.id.to_s}:"
puts " #{new_journal.errors.full_messages.inspect}"
end
end
end