Skip to content

Instantly share code, notes, and snippets.

@rubypanther
Created February 16, 2014 19:08
Show Gist options
  • Save rubypanther/9039102 to your computer and use it in GitHub Desktop.
Save rubypanther/9039102 to your computer and use it in GitHub Desktop.
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