I have an encrypted type in my model
attribute :name, :encrypted
Which is
class EncryptedType < ActiveRecord::Type::Text
And implements #serialize
, #deserialize
, and #changed_in_place?
.
How can I get the raw value from the database before deserialization?
I want to create a rake task to encrypt values which are in the DB that existed before the fields were encrypted. So before the encryption, the name
field contained Bob
. After the code change with encryption, reading that value will produce an error (caught), returning an empty string. I want to read the raw value and set it like a normal attribute so it will encrypt it. After the encryption, the field will look like UD8yDrrXYEJXWrZGUGCCQpIAUCjoXCyKOsplsccnkNc=
.
I want something like user.name_raw
or user.raw_attributes[:name]
.
unencrypted
that process theencrypted
attribute? So you can refer to this method instead of the original attribute. This looks more cohesive, once theencrypt
name means the data will be encrypted. – Coycoyley(instance.attributes_before_type_cast)
is way better readable thany(instance.attributes)
. – Blip