ruby-on-railsruby-on-rails-3ruby-on-rails-4navbargravatar

Gravatar shows hash instead of picture


i want to use gravatar to show pictures on my platform, but instead of doing so i only see the MD5 hash.

Here is my code of "application_helper.rb"

def avatar_url(user)
    gravatar_id = Digest::MD5::hexdigest(user.email).downcase
    "https//www.gravatar.com/avatar/#{gravatar_id}.jpg?d=identical&s=150"
  end
end

I also tried d=mmand d=identicon, which also did not work.

Here is the code im using in the navbar:

<a href="#" class="dropdown-toggle" data-toggle="dropdown"
                  role="button" aria-haspopup="true" aria-expanded="false">
                  <%= image_tag avatar_url(current_user), class: "img-circle" %>&nbsp;
                  <%= current_user.fullname %> <span class="caret"></span>
</a>

Picture of the navbar

Anything i could try?

Thank you for your help :)


Solution

  • Your gravatar URL is wrong, you're missing the : after https. Also the www is not necessary.

    def avatar_url(user)
        gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
        "https://gravatar.com/avatar/#{gravatar_id}.jpg?d=identical&s=150"
      end
    end
    

    https://en.gravatar.com/site/implement/images/ruby/