acts_as_gravatar
acts_as_gravatar provide simple access to gravatar from ActiveRecord. From the email columns (can set it optionally) such as devices, acts_as_gravatar generate a URL of gravatar.
Installation
Add this line to your application's Gemfile:
gem 'acts_as_gravatar'
And then execute:
$ bundle
Or install it yourself as:
$ gem install acts_as_gravatar
Usage
Basic
Call acts_as_gravatar in class of ActiveRecord::Base.
class User < ActiveRecord::Base
acts_as_gravatar
end
The next method becomes to be usable.
user = User.find(1); #
# get profile url of gravatar.
user.gravatar_profile # URL of gravatar profile.
# get image url of gravatar.
user.gravatar_image # URL of gravatar image.
acts_as_gravatar read email
column.(default)
Options
when call acts_as_gravatar, can set default values. (The option not to appoint at the time of acts_as_gravatar summons becomes the default of gravatar.)
class User < ActiveRecord::Base
acts_as_gravatar({
:column => :email, # email column of Model.
:default_image => nil, # default_image.(URL or gravatar default image param.)
:force_default => false, # force the default image.
:image_type => ActsAsGravatar::Enums::ImageType::PNG, # image_type. (JPG/JPEG/GIF/PNG)
:rating => ActsAsGravatar::Enums::Rating::PG, # rating. (G/PG/R/X)
:secure => false, # secure protocol. (https).
:size => 80, # image size.
})
end
Please See Gravatar, Options of gravatar for more detail.
And can set options, when call gravatar_image
or gravatar_profile
.
user = User.find(1); #
# get image url of gravatar.
user.gravatar_image :secure => true, :size => 200
# get profile url of gravatar.
user.gravatar_profile :column => :other_column
API DOCUMENT
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request