Hi, I'd like to create some short urls (6-8 characters) that will act as a look-up key in a database - so they have to be unique.
The two possible ways I am thinking of using: rand(36**8).to_s(36) Digest::SHA1.hexdigest(Time.now.to_s)[0..8] Both of these have a chance of not being unique (I think). Is the best way to check if it is unique to use validates_uniqueness_of(:short_url) and then create the url again if it fails validation? If it is, what is the best way to code this (basically, generate a new short_url if the short_url is not unique). cheers, DAZ -- You received this message because you are subscribed to the Google Groups "DataMapper" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
