Permalink
Browse files

Added avatar to blog comments based on email address associated with …

…a gravatar.
  • Loading branch information...
1 parent 92e128d commit ff795b2ab0040b5846960aeed238d9cd749cdad0 @parndt parndt committed May 27, 2011
Showing with 8 additions and 0 deletions.
  1. +7 −0 app/models/blog_comment.rb
  2. +1 −0 app/views/blog/posts/_comment.html.erb
@@ -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
@@ -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>

0 comments on commit ff795b2

Please sign in to comment.