Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Adds ability to pull back random records from Active Record
Ruby
branch: master

This branch is 99 commits behind spilliton:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
Gemfile
Gemfile.lock
README.md
randumb.gemspec

README.md

randumb

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

This gem requires ActiveRecord version 3.0.0 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

Install

## Add the following to you Gemfile
gem 'randumb'
## Run this
bundle install
Something went wrong with that request. Please try again.