You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# app/models/attributes/content_versions.rb
class Attributes::ContentVersions
include StoreModel::Model
attribute :html, Base64Type.new
attribute :xlsx, Base64Type.new
end
# app/types/base64_type.rb
class Base64Type < ActiveRecord::Type::Value
def type
:base64_string
end
def cast(value)
return if value.blank?
Base64.encode64(value)
end
end
it "should return a summary of the content" do
project = create(:project)
project.content_summary.html = "<html></html>"
expect(project.content_summary.html).to eq("<html></html>")
end
Which gets:
- <html></html>
+ PGh0bWw+PC9odG1sPg==\n
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.
def deserialize(value)
return if value.blank?
Base64.decode64(value)
end
How do we override the deserialiser?
The text was updated successfully, but these errors were encountered:
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:
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?
The text was updated successfully, but these errors were encountered: