PaperClip Gem adds a default attribute called -> _updated_at. What is the use of _updated_at related to paperclip.
Use of _updated_at in paperclip gem (ROR, ruby)
References: https://github.com/thoughtbot/paperclip/blob/main/lib/paperclip/attachment.rb#LL310C4-L315C8
https://www.rubydoc.info/github/thoughtbot/paperclip/Paperclip%2FAttachment:updated_at
I have an updated_at column separately for a model say photo and a column called photo_updated_at gets created as part of the schema. What is the use of this photo_update_at column ?
# Returns the last modified time of the file as originally assigned, and # lives in the <attachment>_updated_at attribute of the model. def updated_at time = instance_read(:updated_at) time && time.to_f.to_i end
the difference between <attachment>_updated_at
and updated_at
is that the second one will be updated any time the modal changes any of the attributes let's say you have added some extra attribute like downloads
to count the times the file has been downloaded or any other thing you want to track, then when you update this or any other attribute it will modify the value of updated_at
to the current time when the model is being updated.
But as PaperClip allows you to have multiple attachments per model, let's say you have a Profile model that allows you to attach an avatar but also allows you to attach something like a pokemon image, then you will have
<Profile
pokemon_img_updated_at:
pokemon_img_file_size:
...the rest of the pokemon attachment related attributes
avatar_updated_at:
avatar_file_size:
...the rest of the avatar attachment related attributes
>
You probably got the idea at this point, the updated_at of each attachment attribute will only be updated when the specific attachment changes, this is mentioned in the Usage section of the github repository https://github.com/thoughtbot/paperclip#usage