Module: HasSecureToken::InstanceMethodsOnActivation

Defined in:
lib/has_secure_token.rb

Instance Method Summary collapse

Instance Method Details

#generate_unique_secure_token(attribute, bytes, key_length) ⇒ Object



46
47
48
49
50
51
# File 'lib/has_secure_token.rb', line 46

def generate_unique_secure_token(attribute, bytes, key_length)
  self.send("#{attribute}=", loop do
    random_token =  SecureRandom.hex(bytes)[0..key_length]
    break random_token unless self.class.exists?(attribute => random_token)
  end)
end