Tip: Ruby On Rails Random Array Element
Posted by anthony crumley, Thu Dec 06 21:56:00 UTC 2007
Rails 2.0 will include an array extension for retrieving a random element. The method name is rand. Since the active record find method returns an array, this method can be used to retrieve a random item from a database. In the following example a featured product will be randomly selected.
Product.find_featured.rand