我希望在从 Rails 模型输出之前对电子邮件地址进行 MD5 哈希处理。目前我的模态看起来像这样:
class Comment < ActiveRecord::Base
belongs_to :post
attr_accessible :body, :name, :reply, :email
validates_presence_of :body, :name
def gravator
require 'digest/md5'
email_address = self.email.downcase
# create the md5 hash
hash = Digest::MD5.hexdigest(email_address)
# compile URL which can be used in <img src="RIGHT_HERE"...
self.email = "http://www.gravatar.com/avatar/#{hash}"
end
end
我想知道将电子邮件字段转换为从 gravator 方法输出的 URL 的最佳方法是什么。
谢谢你的帮助!