-
-
Save jhoolmans/14ed06ea400090606fa3 to your computer and use it in GitHub Desktop.
This file contains 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 | |
#Returns the Gravatar for the given user. | |
def gravatar_for(user, options = { size: 50 }) | |
gravatar_id = Digest::MD5::hexdigest(user.email.downcase) | |
size = options[:size] | |
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}" | |
image_tag(gravatar_url, alt: user.email, class: "img-responsive") | |
end | |
def show_rating_in_stars(rating) | |
rounded = (rating * 2).round / 2.0 | |
rounded = rounded.prettify | |
floored = rounded.floor | |
stars = show_n_stars(floored) | |
stars += image_tag("star-half.png") if rounded > floored | |
stars.html_safe | |
end | |
def show_n_stars(n) | |
images = image_tag("star-on.png") * n | |
return images | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment