audited
audited copied to clipboard
Undefined class/module error
ArgumentError: undefined class/module MyAnyUploader::Uploader70191477934880
This happens when i use audited for versioning model with field which used for CarrierWave. Audited write to audited_changes ruby object(CarrierWave uploader instance).
Error occurs when audited try to load from yaml ruby object and can't find dynamically generated CarrierWave class for object.
Same here.
me too
It's common deserialization problem for objects which doesn't have class in current runtime. I think possible solution can be storing values as primitives(String, DateTime) which always exists.
I know this is pretty old but still open so could be helpful anyway.
I got this Psych monkey patch and add what @korrs mentioned about CarrierWave and could load my audits with uploaders instance properly.
Thanks a lot @korrs!
module Psych
def self.load(yaml, filename = nil, max_retries = 100)
retries = 0
uploader = nil
begin
result = Psych.parse(yaml, filename)
result ? result.to_ruby : result
rescue ArgumentError => e
retries += 1
if e.message.include?('undefined class/module') && retries < max_retries
name = e.message.sub 'undefined class/module ', ''
parts = name.split '::'
if parts.length == 1
klass = parts.only
mod = Module
else
klass = parts[-1]
mod = parts[0..-2].join('::').constantize
end
uploader = mod if klass.include?('Uploader')
mod.const_set(klass, uploader)
retry
end
raise e
end
end
end