def generate_unique_secure_token(attribute)
10.times do |i|
SecureRandom.hex(12).tap do |token|
if exists?(attribute => token)
raise "Couldn't generate a unique token in 10 attempts!" if i == 9
else
return token
end
end
end
end