ruby on rails - Gravatar image not displaying -


i'm working through michael hartl's ruby on rails tutorial, , i've added code display user's gravatar image. doesn't display.

this users helper

module usershelper   # returns gravatar (http://gravatar.com/) 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 

and show.html.erb

<% provide(:title, @user.name) %>  <div class="row">    <aside class="col-md-4">      <section class="user_info">        <h1>          <%= gravatar_for @user %>          <%= @user.name %>        </h1>      </section>    </aside>  </div>

this code when inspect element

    <img alt="humber" class="gravatar" src="https://secure.gravatar.com/avatar/8e92292186fbb306e253b08d0f3eb993">     humber 

this image

your code correct, maybe user using has no email, or email don't have image in gravatar. suggest validate if user have email

def gravatar_for(user)     if user.email?         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")     else         image_tag("/img/avatar_default.png", alt: user.name, class: "gravatar")     end end 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -