Assigning Each User a Unique 100 character Hash in Ruby on Rails -


I have a form on a website that takes some personal information from the visitor, passing this information into another service And I need to assign to each of these forms that 100 characters have unique hash stored in DB with records. What is the optimal way to generate this key and to ensure that it is unique? It is fine that the main auto-pay increase

ActiveSupport :: SecureRandom.hex (50) < P> The chance of not being unique is astronomical.

Optional Simple "Not Scale" race condition failed solution

  Class MyModel & lt; ActiveRecord :: Before Base: Create: Assign_order_token private def assign_unique_token self.unique_token = ActiveSupport :: SecureRandom.hex (50) unique_token? End df unique_token? Self.class.count (: conditions = & gt; {: unique_token = & gt; unique_token}) == 0 and end  

if you actually are sure Make a unique index on the column, and by re-trying to handle a DB specificity error, similar to my implementation above.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -