rahult/random_record — Issue #2: Error raised when the collection is empty.
Author: haydn
Created: 2011-12-05 02:17:06+00:00
State: open

If I use this with a model that doesn't have any records I get this error:

Advertisement.kids_safe.random : Advertisement.randomActionView::Template::Error
(Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near '0.263977116241379' at line 1:
SELECT `advertisements`.* FROM `advertisements`
WHERE `advertisements`.`is_kids_safe` = 1 LIMIT 1 OFFSET 0.263977116241379):

Maybe check if count is 0?

return (limit == 1) ? nil : [] if self.count == 0