I have a form on a website that takes in some personal information from the visitor. I'm passing this information to another service and I need to assign each one of these form submits a 100 character unique hash to be stored in the DB with the record. What's the optimal way to generate this key and make sure it's unique? It's okay if the key auto-increments.
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- facebook error invalid key hash for some devices
- Eager-loading association count with Arel (Rails 3
- Is there a way to remove IDV Tags from an AIFF fil
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
- Factory_girl has_one relation with validates_prese
If you use a Cipher you can encrypt an always different message to get an always different key:
The Ruby standard lib has a module for generating GUIDs:
http://ruby-doc.org/stdlib/libdoc/digest/rdoc/classes/Digest/SHA2.html
Example:
The chance of this not being unique is astronomical.
Alternate simple "does not scale" race condition fail solution.
If you really want to make sure, make an unique index on the column, and handle a DB uniqueness error by retrying, similar to my implementation above.