Displaying 1 result from an estimated 1 matches for "find_by_token".
Did you mean:
find_by_fopen
2005 Jul 26
3
Generating unique random tokens for ActiveRecord objects
I have an ActiveRecord subclass that needs to generate a random (hard
to guess) token for each record in its corresponding table. Currently
I''m doing something like this:
def before_create
self[''token''] = random_value
while self.class.find_by_token(self[''token''])
self[''token''] = random_value
end
end
(random_value is a method that generates a random value for the
token, not surprisingly.)
I can see a potential timing error there if a row gets written
between when I check for...