Skip to content

Instantly share code, notes, and snippets.

@tubbo
Forked from joelbrewer/UsersHelper.rb
Created May 14, 2014 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tubbo/db21fc40ac89ea18d7fa to your computer and use it in GitHub Desktop.
Save tubbo/db21fc40ac89ea18d7fa to your computer and use it in GitHub Desktop.
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
if rounded.is_a? Integer
num_stars = rounded
show_n_stars(num_stars)
else
num_stars = rounded.to_i
show_n_stars(num_stars)
image_tag("star-half.png")
end
end
def show_n_stars(n)
images = ""
n.times do
images += image_tag("star-on.png")
end
images
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment