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
Modify ApplicationRecord
meta-class adding following:
class ApplicationRecord < ActiveRecord::Base
...
def self.random
find(self.pluck(:id).sample)
end
end