Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Created February 27, 2013 03:19
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 mahemoff/5044718 to your computer and use it in GitHub Desktop.
Save mahemoff/5044718 to your computer and use it in GitHub Desktop.
Add sample() to active records to extract random records
class ActiveRecord::Base
class << self
def sample(n=1)
self.order('rand()').first(n)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment