themactep.com

A home of miscellaneous projects by Paul Philippov.

Notes

How to select a random record from data set in Rails

Modify ApplicationRecord meta-class adding following:

class ApplicationRecord < ActiveRecord::Base
  ...

  def self.random
    find(self.pluck(:id).sample)
  end
end