aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Arndt <parndt@gmail.com>2011-05-27 23:41:50 +1200
committerPhilip Arndt <parndt@gmail.com>2011-05-27 23:41:56 +1200
commitff795b2ab0040b5846960aeed238d9cd749cdad0 (patch)
tree001af6dfa945fd5e019ea277b40000a7015d4271
parent92e128d2fbd049c62389598a6c97e6ffd400e2e9 (diff)
downloadrefinerycms-blog-ff795b2ab0040b5846960aeed238d9cd749cdad0.tar.gz
refinerycms-blog-ff795b2ab0040b5846960aeed238d9cd749cdad0.tar.bz2
refinerycms-blog-ff795b2ab0040b5846960aeed238d9cd749cdad0.zip
Added avatar to blog comments based on email address associated with a gravatar.
-rw-r--r--app/models/blog_comment.rb7
-rw-r--r--app/views/blog/posts/_comment.html.erb1
2 files changed, 8 insertions, 0 deletions
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
diff --git a/app/views/blog/posts/_comment.html.erb b/app/views/blog/posts/_comment.html.erb
index ba4a508..17b2002 100644
--- a/app/views/blog/posts/_comment.html.erb
+++ b/app/views/blog/posts/_comment.html.erb
@@ -1,4 +1,5 @@
<article class='blog_comment_message' id='<%= "comment-#{comment.to_param}" %>'>
+ <%= image_tag comment.avatar_url, :alt => comment.name, :class => 'avatar' %>
<%= simple_format auto_link(comment.message.to_s) %>
<footer class='blog_comment_author'>
<p>