4

I'm working through the Michael Hartl Rails Tutorial and I'm getting a weird problem with the 'adding a Gravatar' section. I've checked the code against another implementation of a Gravatar in Rails I did for a different tutorial and don't see what's different.

Basically: the image doesn't appear, but if you right click the space and visit the URL it directs to the correct Gravatar page.

Code: (show.html.erb)

<%= gravatar_for @user %>

Code: (users_helper.rb)

def gravatar_for(user, options = { size: 50 })
    size = options[:size]
    gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
    gravatar_url = "https://secure.gravatar.com/avatars/#{gravatar_id}.png?s=#{size}"
    image_tag(gravatar_url, alt: user.name, class: "gravatar")
end

Totally stumped, know it's probably something really obvious that I'm missing, but from the book and the Gravatar website I seem to have gone about this right...

Alex Lynham
  • 1,318
  • 2
  • 11
  • 29
  • 2
    are you sure the url is right ? the urls I've seen have avatar (singular) in the url, not avatars. – Frederick Cheung Jan 19 '13 at 12:11
  • whats the html code that gets rendered here? – phoet Jan 19 '13 at 14:02
  • @FrederickCheung can't believe it. Checked the link and it was correctly working - but only because Gravatar was automatically handling the incorrect URL. It should have been AVATAR singular as you say, feel like such a chump! – Alex Lynham Jan 20 '13 at 11:30

4 Answers4

7

The url is wrong

gravatar_url = "https://secure.gravatar.com/avatars/#{gravatar_id}.png?s=#{size}"

correct version

gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}.png?s=#{size}"

singular form ".../avatar/...."

ycs1988
  • 83
  • 1
  • 6
4

I had the same issue which I resolved by whitelisting the Cloud9 page in Adblock and ghostery

user1965728
  • 91
  • 2
  • 7
  • I has a similar issue and had to whitelist the site on my "Disconnect" plugin in chrome and then the images loaded as expected. – Spidey Nov 11 '15 at 09:41
0

Is that the whole users_helper.rb file?

Mine look like this:

module UsersHelper

  # Returns the Gravatar (http://gravatar.com/) for the given user.
  def gravatar_for(user)
    gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
    gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
    image_tag(gravatar_url, alt: user.name, class: "gravatar")
  end
end

With the

module UsersHelper

and an extra

end

OnkelK
  • 135
  • 1
  • 2
  • 9
0

The same issue for me. I fixed it by changing gravatar_url to "http://gravatar.com/avatar/#{gravatar_id}", not https connection.