Hey!
I have a headache and this is easier than talking. :) I have not added baked-in avatar support to my application. While there are gems like Paperclip, I haven't added any becuase it is more work.
Instead I use Adorable Avatars:
Adorable avatars do something along the lines of a Ruby symbol. In Ruby, each string has a different ID. It's a different physical bit of memory:
- http://www.reactive.io/tips/2009/01/11/the-difference-between-ruby-symbols-and-strings/
- http://www.troubleshooters.com/codecorn/ruby/symbols.htm
For example:
irb(main):009:0> 'hello'.object_id
=> 70254151744540
irb(main):010:0> 'hello'.object_id
=> 70254151712680
irb(main):011:0> 'hello'.object_id
=> 70254151690460
irb(main):012:0> 'hello'.object_id
=> 70254151674740
Each new string is potentially different, so each new string is given a new bit of memory. A symbol is only declared once:
irb(main):016:0> :hello.object_id
=> 1088668
irb(main):017:0> :hello.object_id
=> 1088668
irb(main):018:0> :hello.object_id
=> 1088668
Each same symbol will have the same ID. Adorable Avatars works along these lines: If you send the same string (it can be any arbitrary string), you will get the same avatar back, no matter what the string might be.
The simplest way to grab an avatar is to append string and size to their API URL:
http://api.adorable.io/avatars/<integer size>/<arbitrary string>.png
Examples include:
http://api.adorable.io/avatars/300/1234567.png
http://api.adorable.io/avatars/100/a1dbao2d20d221d12d12d12d12dk.png
http://api.adorable.io/avatars/150/GIANT_ELEPHANTS_LOL.png
I use Adorable Avatar with Rails' image_tag method:
<%= image_tag "http://api.adorable.io/avatars/#{size}/#{user.login_md5}.png", alt: "#{user.nicename}'s nice avatar." %>
The service is a little slow since there is no way to cache requests from my side, and avatars are generated "live" on each request on theirs, but it works! Unique, dependable avatars.
I don't want to send my user's data, however made-up it is, a third-party service. Instead I send an MD5 hash of the user's username/login. The method is at the bottom of my users controller.