Sounds like you may want to use a before_save
filter to invoke the hash
class method on the Sdel
model prior to saving when the attribute has been modified. Perhaps something along the lines of this:
require 'digest/sha1'
class Sdel < ActiveRecord::Base
attr_accessible :hashed_sdel
before_save { self.hashed_sdel = self.class.hash(hashed_sdel) if hashed_sdel_changed? }
def self.hash(sdel="")
Digest::SHA1.hexdigest(sdel)
end
end
This way, if you have a form that has a text_field
for your hashed_sdel
attribute, it will automatically get run through the hash
class method you have before it the record gets saved (assuming the attribute has changed from it's previous value).