lib/tokenize.rb in jt-rails-tokenizable-1.1.1 vs lib/tokenize.rb in jt-rails-tokenizable-1.1.2
- old
+ new
@@ -36,10 +36,10 @@
def generate_new_token(field)
size = self.class.jt_rails_token_fields[field.to_sym].fetch(:size, 32)
only_digits = self.class.jt_rails_token_fields[field.to_sym].fetch(:only_digits, false)
self[field.to_sym] = loop do
- random_token = only_digits ? SecureRandom.random_number(10**size) : SecureRandom.hex(size)
+ random_token = only_digits ? format("%.#{size}d", SecureRandom.random_number(10**size)) : SecureRandom.hex(size)
break random_token unless self.class.exists?(field => random_token)
end
end
end