Last active
August 29, 2015 14:13
-
-
Save Kameshwaran/42b7c1604d76b7a12fdd to your computer and use it in GitHub Desktop.
simple random implementation in ActiveRecord instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveRecord::Base | |
class << self | |
def random | |
all.at(rand(count)) | |
end | |
end | |
end | |
# User.random => #<User id: 10, ...> | |
# User.random => #<User id: 59, ...> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment