0

I am doing the exersizes of https://www.railstutorial.org/book. I am facing an issue in Chapter 7 at 7.1.4 "A gravatar image and a sidebar" section. Even I have made the appropriate code changes, no gravatar is showing on https://rails-tutorial-zovasilei.c9users.io/users/1. Only the name and the email of the user (with no gravatar) is showing on https://rails-tutorial-zovasilei.c9users.io/users/1.

I am working on cloud9 environment. The app is behaving such as the code has not been refreshed. Thus, I checked that the files have indeed been saved, and double-checked the code, but I do not understand which is the issue as no gravatar still appears.

I quote the code of some files:

routes.rb

Rails.application.routes.draw do
  root 'static_pages#home'
  get  '/help',    to: 'static_pages#help'
  get  '/about',   to: 'static_pages#about'
  get  '/contact', to: 'static_pages#contact'
  get  '/signup',  to: 'users#new'
  resources :users
end

app/views/users/show.html.erb

<% provide(:title, @user.name) %>
<h1>
  <%= gravatar_for @user %>
  <%= @user.name %>
</h1>

app/helpers/users_helper.rb

module UsersHelper

  # Returns the Gravatar 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

app/controllers/users_controller.rb

class UsersController < ApplicationController
  def new
  end

  def show
    @user = User.find(params[:id])
  end

end
4

1 回答 1

0

我解决了这个问题。我在custom.scss中忘记了:

img {
  display: none;
}

上一章中的本教程指示将 img 设置为 none。但是这个 css 规则应该被删除,以便 gravatar 图像可见。

于 2016-10-07T21:16:11.640 回答