Gravatar
The Gravatar field turns an email field from the database into an avatar image if it's found in the Gravatar database.
# app/avo/resources/user.rb
class Avo::Resources::User < Avo::BaseResource
def fields
field :email, as: :gravatar
end
endBy default, the field is labeled "Avatar" and displays a round, 32-pixel image on the index view. On the show view, it displays a square, 340-pixel image. It is hidden on new and edit forms. When no matching avatar exists, Gravatar serves its own default image.
Adjust avatars in the index table
Set rounded to false for square avatars, and use size to change their dimensions. Larger avatars increase the table row height. Neither setting changes the show view.
# app/avo/resources/user.rb
field :email, as: :gravatar, rounded: false, size: 60To open the record when someone clicks its index avatar, enable link_to_record.
# app/avo/resources/user.rb
field :email, as: :gravatar, link_to_record: trueDisplay a fallback image
Provide a default image URL for email addresses without a Gravatar. This fallback applies on both index and show views.
# app/avo/resources/user.rb
field :email, as: :gravatar, default: "https://example.com/images/avatar.png"Build the email address from the record
Use a computed value when the email address is not stored directly in the field's attribute.
# app/avo/resources/user.rb
field :email, as: :gravatar do
"#{record.google_username}@gmail.com"
endFor shared field configuration, see Common field options.