Cannot get Gravatar image to display

Code from the tutorial:

module AvatarHelper
  def avatar(user)
    email_digest = Digest::MD5.hexdigest(user.email)
    gravatar_url = "https://gravatar.com/gravatar/#{email_digest}"

    image_tag(gravatar_url)
  end
end

Browser shows this:

Generated HTML is:

<img src="https://gravatar.com/gravatar/dffd0b1c36bd23ce08a438c8157ec16f" alt="Dffd0b1c36bd23ce08a438c8157ec16f">

When I browse to the image link manually, the Gravatar appears. But the app is showing the ‘alt’ instead of the image.

I’m sure it’s something real stupid I’m doing. :joy:

Anyway, thanks in advance for any tips.

/Hunt

Can you show me the contents of your app/views/shouts/_shout.html.erb file?

Mine looks like this:

<div>
  <%= avatar(shout.user) %>
  <%= link_to shout.username, shout.user %>
  <%= render shout.content %>
  <%= link_to shout do %>
    <%= time_ago_in_words(shout.created_at) %> ago
  <% end %>
  <%= like_button(shout) %>
</div>

@pbmarcano, here you go. Looks to be the same as yours:

<div>
  <%= avatar(shout.user) %>
  <%= link_to(shout.username, shout.user) %>
  <%= render shout.content %>
  <%= link_to(shout) do %>
      <%= time_ago_in_words(shout.created_at) %> ago
  <% end %>

  <%= like_button(shout) %>
</div>

Not sure when this lesson was created, but did the API for fetching a Gravatar image change when Wordpress took over Gravatar?

Woops! Found the difference between our two apps.

Remove the https: at the beginning of your gravatar_url string in your AvatarHelper module.

My finished product is up in a heroku instance at http://90stwitter.com, you can compare the generated html there.

Also, Gravatar was acquired by Automattic in 2007, and this course was updated for Rails 5 earlier this year. I think the API is pretty stable at this point.

Thank you , kindly. Simple and careless URL issue on my part.

1 Like