diff --git a/app/models/user.rb b/app/models/user.rb index 5110ea7f..70f0781a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,5 @@ +require 'digest/md5' + ## # a person using the Indent web application. Owns all other content. class User < ActiveRecord::Base @@ -35,6 +37,10 @@ class User < ActiveRecord::Base super(options) end + def name + self[:name] || 'Anonymous author' + end + def content { characters: characters, @@ -57,6 +63,12 @@ class User < ActiveRecord::Base ].sum end + def image_url(size=80) + email_md5 = Digest::MD5.hexdigest(email.downcase) + # 80px is Gravatar's default size + "https://www.gravatar.com/avatar/#{email_md5}?d=identicon&s=#{size}".html_safe + end + private # Attributes that are non-public, and should be blacklisted from any public diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index db0a0e34..5aa16744 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,12 +1,15 @@