Created
March 22, 2015 14:31
-
-
Save andersr/d7475444ee9f8bba602c to your computer and use it in GitHub Desktop.
Generate token id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
before_save :generate_token_id | |
def to_param | |
token_id | |
end | |
protected | |
def generate_token_id | |
begin | |
self[:token_id] = SecureRandom.urlsafe_base64(8) | |
end while Model.exists?(:token_id => self[:token_id]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment