Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 1.21 KB

README.md

File metadata and controls

45 lines (32 loc) · 1.21 KB

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