# Gravtastic The super fantastic way of getting Gravatars. By [Chris](http://chrislloyd.com.au). In less than 5 minutes you can add Gravatars to your Ruby project. It works in Rails, Merb _and_ plain ol' Ruby. The best way to learn more about Gravtastic is to [look at the source](http://github.com/chrislloyd/gravtastic/blob/master/lib/gravtastic.rb). It's one file, about 80 LOC and really pretty simple. If that isn't for you, then follow the instructions below! ## Install sudo gem install gravtastic ## Usage Add this to your `environment.rb`: config.gem 'gravtastic', :version => '>= 2.1.0' Next, say that you want a Gravatar for your model: class User < ActiveRecord::Base is_gravtastic! end And you are done! In your views you can now use the `#gravatar_url` method: <%= image_tag @user.gravatar_url %> If you want to change the image, you can do this: <%= image_tag @user.gravatar_url(:rating => 'R', :secure => true) %> That will show R rated Gravatars over a secure connection. If you find yourself repeating that all around your app, you can set the Gravatar defaults. In your model, just change the `is_gravtastic!` line to something like this: is_gravtastic :author_email, :secure => true, :filetype => :gif, :size => 120 Now all your Gravatars will come from a secure connection, be a GIF and be 120x120px. The email will also come from the `author_email` field, not the default `email` field. Don't worry, you arn't locked into these defaults (you can override them by passing options to `#gravatar_url` like before). _Note: You can use either `is_gravtastic!` or `is_gravtastic`, they both do the same thing._ ### Plain Ruby So you just have a regular ol' Ruby app? No Rails and ActiveRecord? require 'gravtastic' class BoringUser include Gravtastic is_gravtastic! end And wallah! That works exactly the same as in Rails! Now all instances of the BoringUser class will have `#gravatar_url` methods. _Note: the `#gravatar_url` methods don't get included until you specify the class `is_gravtastic!`_ ### Complete List of Options
Option | Description | Default | Values | |
---|---|---|---|---|
secure | Gravatar transmitted with SSL | false | true/false | |
size | The size of the image | 80 | 1..512 | |
default | The default avatar image | none | Any URL, or "identicon", "monsterid", "wavatar" | |
rating | The lowest level of ratings you want to allow | G | G, PG, R or X | |
filetype | The filetype of the image | png | gif, jpg or png |