Skip to content

Instantly share code, notes, and snippets.

@r38y
Created October 8, 2009 00:54
Show Gist options
  • Save r38y/204611 to your computer and use it in GitHub Desktop.
Save r38y/204611 to your computer and use it in GitHub Desktop.
def generate_slug
while slug.blank? || self.class.count(:conditions => ['slug = ?', slug]) > 0
self.slug = Digest::SHA1.hexdigest([Time.now.to_s, (1..10).map{ rand.to_s }].flatten.join('--'))[0, 10]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment