Skip to content

Instantly share code, notes, and snippets.

@teaforthecat
Last active December 11, 2015 06:09
Show Gist options
  • Save teaforthecat/4557534 to your computer and use it in GitHub Desktop.
Save teaforthecat/4557534 to your computer and use it in GitHub Desktop.
Store the processed image on the datastore before being served by dragonfly (pre-caching). The url needs to be accesses programatically, like in a background job.
# store the job before it has a chance to be served by dragonfly
images.configure do |c|
c.define_url do |app, job, opts|
thumb = ThumbTracker.where(job: job.serialize).first
unless thumb
uid = job.store
thumb = ThumbTracker.create!(
:uid => uid,
:job => job.serialize
)
end
n = ['', 0, 1, 2].sample
app.datastore.url_for(thumb.uid, host: "cdn#{n}.s3.aws.com")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment