Skip to content

Instantly share code, notes, and snippets.

@kpumuk
Forked from mdarby/gist:43082
Created January 28, 2009 19:28
Show Gist options
  • Save kpumuk/54141 to your computer and use it in GitHub Desktop.
Save kpumuk/54141 to your computer and use it in GitHub Desktop.
# Usage:
# >> User.random
# => #<User login: ...
class ActiveRecord::Base
def self.random
find(rand(count))
rescue ActiveRecord::RecordNotFound
retry
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment