Skip to content

Instantly share code, notes, and snippets.

@romiras
Created April 29, 2024 09:17
Show Gist options
  • Save romiras/587c5cefd1e58bd88376a178ac48ebf7 to your computer and use it in GitHub Desktop.
Save romiras/587c5cefd1e58bd88376a178ac48ebf7 to your computer and use it in GitHub Desktop.
A hack to fix class dynamically in YaML-serialized attribute, Ruby on Rails
def raw_object
self[:raw_object]
rescue ArgumentError => e
raw = raw_object_before_type_cast
raw.gsub!(%r{!ruby/object:MyNamespace::Fixme}, '!ruby/object:MyNamespace::Corrected')
Psych.load(raw, symbolize_names: true)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment