Best way to create unique token in Rails?
问题 Here\'s what I\'m using. The token doesn\'t necessarily have to be heard to guess, it\'s more like a short url identifier than anything else, and I want to keep it short. I\'ve followed some examples I\'ve found online and in the event of a collision, I think the code below will recreate the token, but I\'m not real sure. I\'m curious to see better suggestions, though, as this feels a little rough around the edges. def self.create_token random_number = SecureRandom.hex(3) \"1X#{random_number}