Created
April 29, 2024 09:17
-
-
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
This file contains 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
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