From ff795b2ab0040b5846960aeed238d9cd749cdad0 Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Fri, 27 May 2011 23:41:50 +1200 Subject: Added avatar to blog comments based on email address associated with a gravatar. --- app/models/blog_comment.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/models') diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index 13aceb1..f461cdb 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -19,6 +19,13 @@ class BlogComment < ActiveRecord::Base scope :approved, :conditions => {:state => 'approved'} scope :rejected, :conditions => {:state => 'rejected'} + def avatar_url(options = {}) + options = {:size => 60} + require 'digest/md5' + options[:size] = "?s=#{size}" if options[:size] + "http://gravatar.com/avatar/#{Digest::MD5.hexdigest(self.email.to_s.strip.downcase)}#{size}.jpg" + end + def approve! self.update_attribute(:state, 'approved') end -- cgit v1.2.3