Skip to content

Instantly share code, notes, and snippets.

@mattlenz
Last active October 8, 2015 19:08
Show Gist options
  • Select an option

  • Save mattlenz/3375756 to your computer and use it in GitHub Desktop.

Select an option

Save mattlenz/3375756 to your computer and use it in GitHub Desktop.
Memoize dragonfly image dimensions
class User < ActiveRecord::Base
image_accessor :avatar
serialize :avatar_geometries, Hash
def avatar_dimensions(geometry)
unless avatar_geometries.has_key?(geometry)
thumb = avatar.thumb(geometry)
avatar_geometries[geometry] = {
width: thumb.width,
height: thumb.height
}
save
end
OpenStruct.new(avatar_geometries[geometry])
end
end
@kayluhb
Copy link

kayluhb commented Apr 17, 2013

I believe geometries on lines 10 & 18 should be avatar_geometries no?

@mattlenz
Copy link
Author

mattlenz commented Mar 3, 2014

@kayluhb Fixed, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment