Skip to content
/ randumb Public
forked from spilliton/randumb

Adds ability to pull back random records from Active Record

Notifications You must be signed in to change notification settings

dbi/randumb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

randumb

randumb is a ruby gem that allows you to pull random records from ActiveRecord...fast!

This gem requires rails 3 or greater.

I built this for use on Compare Vinyl. Check out the homepage to see it in action :)

Example Usage

## randumb works the same as active records "all, first, and last" methods
## with no params, it will pull back one random record
Artist.random
## you can also put it at the end of scopings and relations
## passing an integer will pull that many records back in random order (unless your query brings back less records)
Artist.has_views.includes(:albums).random(10)
## returns a record if called without parameters
artist = Artist.random ## instead of artist = Artist.random.first

## returns an array if called with parameters
artists = Artist.random(3)  ## returns an array
artists = Artist.random(1)  ## returns an array
## you can use offset method for generating a random record for possibly improved performance on large datasets
artist = Artist.random(3, :method => :offset)

Install

## Add the following to you Gemfile
gem 'randumb'
## Run this
bundle install

About

Adds ability to pull back random records from Active Record

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%