没有为用户显示头像
No gravatar is showing for the user
我正在做 https://www.railstutorial.org/book 的运动量。
我在第 7 章的 7.1.4 "A gravatar image and a sidebar" 部分遇到了一个问题。
即使我进行了适当的代码更改,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.
上也没有显示任何头像
我正在使用 cloud9 环境。该应用程序的行为类似于代码尚未刷新。因此,我检查了文件确实已保存,并仔细检查了代码,但我不明白是哪个问题,因为仍然没有出现头像。
我引用部分文件的代码:
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
我解决了这个问题。我忘记了 custom.scss:
img {
display: none;
}
本教程在上一章中介绍将 img 设置为 none。
但是这个 css 规则应该被删除,这样才能看到头像。
我正在做 https://www.railstutorial.org/book 的运动量。 我在第 7 章的 7.1.4 "A gravatar image and a sidebar" 部分遇到了一个问题。 即使我进行了适当的代码更改,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.
上也没有显示任何头像我正在使用 cloud9 环境。该应用程序的行为类似于代码尚未刷新。因此,我检查了文件确实已保存,并仔细检查了代码,但我不明白是哪个问题,因为仍然没有出现头像。
我引用部分文件的代码:
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
我解决了这个问题。我忘记了 custom.scss:
img {
display: none;
}
本教程在上一章中介绍将 img 设置为 none。 但是这个 css 规则应该被删除,这样才能看到头像。