Skip to content

Instantly share code, notes, and snippets.

@rubypanther
Forked from grauschnabel/api key
Created February 16, 2014 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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