Created
February 16, 2014 19:08
-
-
Save rubypanther/9039102 to your computer and use it in GitHub Desktop.
This file contains 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
class ApiKey < ActiveRecord::Base | |
belongs_to :user | |
around_create :generate_api_key | |
def generate_api_key | |
self.api_key = "" | |
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-.," | |
(1..24).each do | |
self.api_key += chars[rand(chars.length)-1] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment