I am on development environment on localhost:3000
I followed railscasts episode on Gravatar. I am trying to set my custom avatar image that is located in assets/images.
The code I use is this:
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".
I changed default_url to:
default_url = "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.
Any clue whats wrong?
Thanks
I should comment on your question but my reputation does not allow me. You try with "gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"???
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."
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.
It looks like your url is wrong, try:
For reference this is my Users Helper:
You can add options[:default] = image_tag("Yourimage.png") to change the default picture.