Paperclip attachment not using proper updated_at time for query string

Viewed 1087

I'm using Rails + Paperclip + S3. I'm looking to host my assets to Cloudfront using one of my S3 buckets.

I know that Cloudfront caches assets but that you can break that cache by configuring it to forward query strings from the origin.

When I modify an asset I expect this to happen

  1. The updated_at timestamp of the ActiveRecord object is updated.
  2. Paperclip updates the query string of the image on S3 to reflect the new updated_at time.
  3. Cloudfront serves the new image because of the new timestamp query string.

However, it looks like Paperclip isn't properly updating the updated_at timestamp. Maybe it's cached somehow. Therefore the query string doesn't update and Cloudfront never breaks the cache.

My model is:

class UserImage < ActiveRecord::Base
  has_attached_file :image
end

>> ui = UserImage.find(576925)
>> ui.image.class
=> Paperclip::Attachment

>> ui.touch

>> ui.updated_at.to_i
=> 1386241041

>> ui.image.updated_at
=> 1386240937

Those two updated_at timestamps should be the same.

1 Answers
Related