我在做https://www.railstutorial.org/book的exersizes。 我在第7章7.1.4「Gravatar image and a sidebar」一節中遇到了一個問題。 即使我已經做出了相應的代碼更改,https://rails-tutorial-zovasilei.c9users.io/users/1上沒有顯示gravatar。在https://rails-tutorial-zovasilei.c9users.io/users/1上只顯示用戶的姓名和電子郵件(沒有gravatar)。沒有顯示給用戶的gravatar
我正在研究cloud9環境。該應用的行爲如代碼尚未刷新。因此,我檢查了文件確實已經保存了,並且仔細檢查了代碼,但我不明白哪個是問題,因爲還沒有出現gravatar。
我引用了一些文件的代碼:
的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
應用程序/視圖/用戶/ show.html.erb
<% provide(:title, @user.name) %>
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
應用/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
應用程序/控制器/ users_controller.rb
class UsersController < ApplicationController
def new
end
def show
@user = User.find(params[:id])
end
end
我測試過你的'gravatar_for(user)'並且它正在工作。你確定用戶的電子郵件是通過gravatar註冊的,並確實上傳了一張照片? – mrvncaragay
感謝您對它進行測試。我已經在gravatar註冊了用戶的電子郵件,並且還上傳了一張照片。真奇怪。 –
我在我的本地存儲庫中運行代碼而不是c9。也許它有問題與c9 idk – mrvncaragay