Created
May 20, 2015 10:15
-
-
Save adambutler/9e84286ee3ead50391fe to your computer and use it in GitHub Desktop.
Generate a UID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_uid | |
self.uid = loop do | |
uid = SecureRandom.urlsafe_base64(nil, false) | |
break uid unless Model.exists?(uid: uid) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment