문제

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,

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top