Skip to content

How to: ensure file uniqueness.

lafeber edited this page Nov 14, 2012 · 1 revision

Add a md5hash field to your model, then put the following code in your model:

before_validation :compute_hash
validates_uniqueness_of :md5hash, :on => :create

def compute_hash
  self.md5hash = Digest::MD5.hexdigest(self.data.read)
end
Clone this wiki locally