Gravatar-设置自定义默认头像-未显示头像 [英] Gravatar - setting custom default avatar - avatar not shown

查看:140
本文介绍了Gravatar-设置自定义默认头像-未显示头像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在localhost:3000上的开发环境上

I am on development environment on localhost:3000

我在Gravatar上关注了Railscasts的一集.我正在尝试设置位于资产/图像中的自定义头像图像.

I followed railscasts episode on Gravatar. I am trying to set my custom avatar image that is located in assets/images.

我使用的代码是这样:

  def avatar_url(user)
    gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
    default_url = "#{root_url}assets/AwesomeAvatar.png"
    "http://gravatar.com/avatar/#{gravatar_id}.png?s=100&r=g&d=#{CGI.escape(default_url)}"
  end

化身未加载.当我尝试保存图像时,出现错误:失败-没有文件".

The avatar does not load. When I try to save the image there is an error: "Failed - No file".

我将default_url更改为:

I changed default_url to:

    default_url = "http://localhost:3000/assets/AwesomeAvatar.png"

当我转到该URL时,我看到了头像的图像,但是我仍然遇到相同的错误,并且头像未加载.我也尝试将d设置为: d="http://localhost:3000/assets/AwesomeAvatar.png"d=#{CGI.escape("http://localhost:3000/assets/AwesomeAvatar.png")},但也没有头像加载的运气.

When I go to this url i see the avatar's image but I still get the same error and the avatar does not load up. I also tried setting d as: d="http://localhost:3000/assets/AwesomeAvatar.png" and d=#{CGI.escape("http://localhost:3000/assets/AwesomeAvatar.png")} but no luck having the avatar load either.

有什么线索吗?

谢谢

推荐答案

Gravatar的网站说,您指定的默认图像必须公开可用(例如,不能在Intranet,本地开发计算机上,HTTP Auth或其他版本之后)防火墙等).默认图片会通过安全扫描传递,以避免恶意内容."

Gravatar's site says the default image you specify "MUST be publicly available (e.g. cannot be on an intranet, on a local development machine, behind HTTP Auth or some other firewall etc). Default images are passed through a security scan to avoid malicious content."

用于默认映像的url托管在本地的开发环境中,因此将失败.要使其正常工作,您需要将默认图像托管在公共位置,并使用该公共URL作为默认图像.

The url you are using for your default image is hosted in your development environment on localhost, so that will fail. To make it work you need to host the default image somewhere public and use that public URL for the default.

这篇关于Gravatar-设置自定义默认头像-未显示头像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆