Currently I have Gravatar implemented on my site this way:

In application_helper.rb:

  def avatar_url(user)
    default_url = "#{root_url}images/guest.png"
    gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
    "http://gravatar.com/avatar/#{gravatar_id}.png?s=200{CGI.escape(default_url)}"
  end

In my _nav.html.erb view:

<%= image_tag avatar_url(current_user), :class => 'gravatar' %>

What's the best way to customize the default gravatar URL that shows up if a user doesn't have one associated to their email address?

有帮助吗?

解决方案

check out https://github.com/mdeering/gravatar_image_tag, then you can do something as simple as

image_url =  GravatarImageTag::gravatar_url(user.email, :d => :identicon)

this is what I have in my initializer:

 GravatarImageTag.configure do |config|
   config.default_image           = :identicon   
   config.filetype                = nil   
   config.include_size_attributes = true  
   config.rating                  = nil   
   config.size                    = nil   
   config.secure                  = false 
 end
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top