public
Description: Rails plugin to pick random items from a model (without using :order => "RAND()")
Homepage:
Clone URL: git://github.com/porras/random_items.git
ferblape (author)
Tue Jun 16 01:19:01 -0700 2009
commit  79943eb6cbadc4b55f158a4e9fcde6206c60fa51
tree    477b26c581a403725968ba7e832192c7207759d5
parent  3aaa4636d12318b890065aac703cddc6b3d851d9
README
*random_items* is a Rails plugin which allows to pick random items from an ActiveRecord model (without using <tt>:order 
=> "RAND()"</tt> which is not a good idea in terms of performance).

The interface is almost the same as that of <tt>ActiveRecord::Base.find</tt>.

Some examples:

Picking a random item:

  Model.random(:first)

Picking 5 random items:

  Model.random(:all, :limit => 5)

Pickings a random item using standard <tt>ActiveRecord::Base.find</tt> options, such as <tt>:include</tt>

  Model.random(:first, :include => :relation)


In that last case, you are expected not to use options which don't make sense, such as <tt>:order</tt> =;-)


Copyright (c) 2008 Sergio Gil, released under the MIT license