Module: PickARecord::InRandomOrder::ClassMethods
- Defined in:
- lib/pick_a_record/in_random_order.rb
Instance Method Summary collapse
-
#first_random(n = 1) ⇒ ActiveRecord::Relation
Return the first ‘n` record(s) in random order.
- #in_random_order ⇒ ActiveRecord::Relation
Instance Method Details
#first_random(n = 1) ⇒ ActiveRecord::Relation
Return the first ‘n` record(s) in random order.
8 9 10 11 12 |
# File 'lib/pick_a_record/in_random_order.rb', line 8 def first_random(n = 1) n = n.to_i.nonzero? || 1 limit(n).in_random_order end |
#in_random_order ⇒ ActiveRecord::Relation
15 16 17 |
# File 'lib/pick_a_record/in_random_order.rb', line 15 def in_random_order reorder(connection.random_function) end |