我遵循 Railscast 教程来使用 gravatar,它对我有用,但如果是默认图像,它没有显示它,我的代码有什么错误?
def avatar_url(user)
default_url = "#{root_url}images/user_avatar_small.png"
gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
"https://secure.gravatar.com/avatar/#{gravatar_id}.png?s=48&d=#{CGI.escape(default_url)}"
end
此外,如果使用 "http://gravatar.com/avatar/#{gravatar_id}.png?s=48&d=#{CGI.escape(default_url)}"
默认图像则不显示并且我正在使用 devise gem
我检查了浏览器检查器,发现此错误GET http://i0.wp.com/localhost/images/user_avatar_small.png 404(未找到)
最佳答案
我猜这是因为您的应用程序中缺少主机配置。
有不同的选项可以实现此目的:How do I configure the hostname for Rails ActionMailer? How do I set default host for url helpers in rails?
关于ruby-on-rails - 头像默认图片不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20207009/