Skip to content

Instantly share code, notes, and snippets.

@msroot
Created July 27, 2013 05:44
Show Gist options
  • Save msroot/6093908 to your computer and use it in GitHub Desktop.
Save msroot/6093908 to your computer and use it in GitHub Desktop.
class App < ActiveRecord::Base
before_create :generate_hash_id
private
def generate_hash_id
begin
self.hash_id = SecureRandom.hex(30)
end while self.class.exists?(hash_id: hash_id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment