Created
December 10, 2008 18:59
-
-
Save inre/34440 to your computer and use it in GitHub Desktop.
This file contains 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_token(length=8) | |
alphanumerics = ('a'..'z').to_a.concat(('A'..'Z').to_a.concat(('0'..'9').to_a)) | |
self.token = alphanumerics.sort_by{rand}.to_s[0..length] | |
# Ensure uniqueness of the token.. | |
generate_token unless Widget.find_by_token(self.token).nil? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment