Gravity
Gravity is a simple Gravatar plugin for Rails. It allows you to easily get Gravatar images and profile informations.
Installation
Just add it to your Gemfile like this:
gem "gravity"
and you're ready to go.
Usage
In your model:
class User < ActiveRecord::Base
has_gravatar
end
In your views:
<%= image_tag @user.gravatar_image %>
<%= @user.gravatar_profile['displayName'] %>
This works if you have an email
field in your model. To use a different field for email, pass the field name to the :email
option:
class User < ActiveRecord::Base
has_gravatar :email => :email_address
end
You can also pass options to the ´gravatar_image´ and ´gravatar_profile´ methods:
<%= image_tag @user.gravatar_image :size => 40, :default => 'identicon' %>
<%= @user.gravatar_profile(:secure => true)['displayName'] %>
Here is a complete list of options:
Option | Description | Default | Values |
---|---|---|---|
secure | Use SSL to call gravatar.org | false | true/false |
size | The size of the image | 80 | 1..512 |
default | The avatar image used by default | none | "404", "mm", "identicon", "monsterid", "wavatar", "retro" or an absolute URL (this must start with "http"). |
rating | The lowest level of ratings you want to allow | G | G, PG, R or X |
forcedefault | Force usage of the default image | false | true/false |
See the Gravatar site for more informations.
Copyright (c) 2011 Giuseppe Capizzi, released under the MIT license