Open barnaclebarnes opened 1 year ago
Hi @barnaclebarnes! Sorry it took me too long to respond 😞 The problem is that Rails (it's a Rails code, gem has nothing to do with it) uses cast
/cast_value
for both encoding and decoding so we have to do something like this:
class Base64Type < ActiveRecord::Type::Value
def type
:base64_string
end
def cast(value)
return if value.blank?
if base64?(value)
Base64.decode64(value)
else
Base64.encode64(value)
end
end
private
def base64?(value)
value.is_a?(String) && Base64.encode64(Base64.decode64(value)) == value
end
end
We do the same dirty hack in One implementation
I have the following:
Which gets:
It seems that I can encode the values to the fields but cannot decode the values. I tried putting this in the
base64_type.rb
but that didn't seem to get called.How do we override the deserialiser?