the email you provided must have an account on gravatar so you can render the custom image ,if it's not registered in gravtar ,it will provide the default image for you ,try with registered emails
Rails: Setting up a gravatar image for user profile
-
11-06-2023 - |
题
I'm working through the Michael Hartl's Ruby on Rails Tutorial to add a Gravatar image to the user profile.
Here is my code:
#app/views/users/show.html.erb
<% provide(:title, @user.name) %>
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
And helper:
#app/helpers/users_helper.rb
module UsersHelper
# Returns the Gravatar (http://gravatar.com/) 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
end
And then I have used update_attributes to update the user in the database:
$ rails console
>> user = User.first
>> user.update_attributes(name: "Example User",
?> email: "user@myapplication.com",
?> password: "password",
?> password_confirmation: "password")
=> true
So after that when I access the show page of user profil, I only have the original gravatar image, but not the custom gravatar associated with the user email.
What can be wrong?
Thanks,
解决方案
不隶属于 StackOverflow