I'm using the has_attached_file from paperclip gem to calculate a checksum on the file's content. By default, this calculation will be applied to the column that has the name fingerprint on it but the problem is that I have two columns that must have "fingerprint" in the name. Is there a way to specify in which column Paperclip should calculate the checksum?
here's what I've tried
has_attached_file(
:file,
{
hash_digest: Digest::SHA256,
hash_digest_column: :original_file_fingerprint
}
)
but nothing gets updated. Any ideas? https://github.com/thoughtbot/paperclip#checksum--fingerprint
So first, there's no problem having multiple columns ending in
_fingerprint, Paperclip only uses the column named after the attachment, ie.file_fingerprintforhas_attached_file :file.Second, Paperclip doesn't actually care about columns, it cares about attribute getters/setters, so if you have to conform to some legacy database schema that uses
file_fingerprintfor something else, then you can always just redefine the attribute methods to use a different column.There are two options depending on whether you still need access to (the actual)
file_fingerprintfrom your Rails model.If you don't need access to it:
If you do (these will not change/alter Rails DB query syntax, like
create,update,whereclauses etc):