Last active
December 17, 2015 03:09
-
-
Save delba/5541314 to your computer and use it in GitHub Desktop.
Gravatar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Gravatar | |
| BASE_URL = "http://www.gravatar.com/avatar".freeze | |
| def gravatar_url(options = {}) | |
| "#{BASE_URL}/#{email_hash}?#{options.to_query}" | |
| end | |
| private | |
| def email_hash | |
| Digest::MD5.hexdigest(email) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User < ActiveRecord::Base | |
| include Gravatar | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module UsersHelper | |
| def gravatar_for(user, size: "80", alt: user.username) | |
| image_tag user.gravatar_url(size: size), size: size, alt: alt | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment