Recreating journal sub classes if Journal was reloaded

pull/41/head
Gregor Schmidt 13 years ago
parent ee543489f1
commit 124b559faa
  1. 15
      vendor/plugins/acts_as_journalized/lib/acts_as_journalized.rb

@ -85,7 +85,20 @@ module Redmine
def journal_class
journal_class_name = "#{name.gsub("::", "_")}Journal"
if Object.const_defined?(journal_class_name)
Object.const_get(journal_class_name)
jclass = Object.const_get(journal_class_name)
if jclass.superclass == Journal
jclass
else
# We are running into some nasty reloaded things in here. Journal
# is a reloaded version, jclass.superclass is an older version
# from a previous request.
#
# So we are just removing the const and triggering ourselves
# recursively to create a new up-to-date version of the
# journal_class with working superclass pointers.
Object.send :remove_const, journal_class_name
journal_class
end
else
Object.const_set(journal_class_name, Class.new(Journal)).tap do |c|
# Run after the inherited hook to associate with the parent record.

Loading…
Cancel
Save