Generating Guids in Ruby

后端 未结 10 1863
南笙
南笙 2020-11-27 10:53

I have problem that is really easily solved with Guids.

In particular, for a password reset workflow, I would like to send a Guid token to a user\'s email and have

10条回答
  •  被撕碎了的回忆
    2020-11-27 11:30

    While programming late at night I came up with the following solution (based off Simone's) for generating a unique GUID in Rails. I am not proud of it but it does work quite well.

    while Order.find_by_guid(guid = rand(36**8).to_s(36).upcase).present?; end
    

提交回复
热议问题