Skip to content

porras/random_items

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

*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

About

Rails plugin to pick random items from a model (without using :order => "RAND()")

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages