Created
March 11, 2019 09:19
-
-
Save webzorg/15c72655186119b568ab3b50469234c8 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
class Model < ApplicationRecord | |
has_many :tags | |
def generate_tag | |
tag = loop do | |
tag = (SecureRandom.random_number(9e9) + 1e9).to_i # 9 digit random int | |
break tag unless Tag.exists?(tag: tag) | |
end | |
tags.create(tag: tag) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment