Fixed avatar_url so it (1) uses the correct Gravatar URL syntax, (2) actually respects the :size option, and (3) supports a custom default image.
This commit is contained in:
parent
2bff0b207f
commit
6a5afeaa19
1 changed files with 9 additions and 3 deletions
|
@ -20,10 +20,16 @@ class BlogComment < ActiveRecord::Base
|
||||||
scope :rejected, :conditions => {:state => 'rejected'}
|
scope :rejected, :conditions => {:state => 'rejected'}
|
||||||
|
|
||||||
def avatar_url(options = {})
|
def avatar_url(options = {})
|
||||||
options = {:size => 60}
|
|
||||||
require 'digest/md5'
|
require 'digest/md5'
|
||||||
size = ("?s=#{options[:size]}" if options[:size])
|
params = {
|
||||||
"http://gravatar.com/avatar/#{Digest::MD5.hexdigest(self.email.to_s.strip.downcase)}#{size}.jpg"
|
s: options[:size] || 60,
|
||||||
|
d: options[:default_image]
|
||||||
|
}
|
||||||
|
query_string = params.map do |k,v|
|
||||||
|
[k,v].map { |s| CGI::escape(s.to_s) }.join('=')
|
||||||
|
end.join('&')
|
||||||
|
email_md5 = Digest::MD5.hexdigest(self.email.to_s.strip.downcase)
|
||||||
|
"http://gravatar.com/avatar/#{email_md5}?#{query_string}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def approve!
|
def approve!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue