How would you do it?
That way you don't have the indirection of an ActiveRecord callback and you have your process of creating a request and assigning it a unique hash in a straightforward single process.
James Golick has a great blog post on that approach at http://jamesgolick.com/2010/3/14/crazy-heretical-and-awesome...
class Request < ActiveRecord::Base
end
class RequestValidation < Aspector::Base
target do
def has_unique_hash_id?
exists?(:hash_id => hash_id)
end
end
before :create do
hash_id = SecureRandom.hex(12) until has_unique_hash_id?
end
endRequestValidation.apply(Request)
Edit: Nevermind, I realize now that SecureRandom's uuid isn't really a uuid, in that sense. It's just random.