Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fourcolors/d8e7464e3aacb07030a5b2fa223e4a67 to your computer and use it in GitHub Desktop.
Save fourcolors/d8e7464e3aacb07030a5b2fa223e4a67 to your computer and use it in GitHub Desktop.
@seller.user_info_token = loop do
token = SecureRandom.urlsafe_base64
break token unless User.exists?(user_info_token: token)
end
@fourcolors
Copy link
Author

before_save :generate_code

def generate_code
  self.code = SecureRandom.urlsafe_base64
  generate_code if Code.exists?(code: self.code)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment