Think In Geek

In geek we trust

July 4th, 2011

Easily select random records in rails

If you ever wondered how to easily retrieve a random record in an ActiveRecord model, here’s en easy way to do that: use the sample method. sample is a class method from the Array class that retrieves one or more random items from an array instance. It conveniently returns nil or an array lesser than […]

, , ,