to_gravatar

To install… add the following to your Gemfile:

gem ‘to_gravatar’

…and run ‘bundle install’.

Then, simply add “has_gravatar” to any model with an :email property. Optionally, you may pass in some other property name which includes the email address… something like:

class User < ActiveRecord::Base

attr_accessible :some_other_field, :password, :password_confirmation, :remember_me

has_gravatar :field => “some_other_field”

end

In your views… @user.to_gravatar will return the url to the user’s Gravatar. So you can do something like:

image_tag @user.to_gravatar

You can also add options for the size, default image, rating restriction, ssl. Example:

class User < ActiveRecord::Base

attr_accessible :some_other_field, :password, :password_confirmation, :remember_me

has_gravatar :field => “some_other_field”, ### field containing email address. default to :email.

:default => "http://example.com/example_image.jpg", ### url of default image
:rating => "g",   ### options are "g", "pg", "r", and "x".  default to "r".
:size => 100,  ### pixels square.  default to 80px.
:ssl => true ### use https, avoid popups.  defaults false.

end