From the documentation:
The argument n indicates the length of a random length. The result string is two times longer than n.
So, if you want 45, you can set it to 23, which will return 46 characters and then take the first 45. Of course, the first five characters of the long string will work too.
ActiveSupport::SecureRandom.hex(23)[0...45]
source
share