Need to get a random record? Fortunately databases have built-in functions for this.
# For PostgreSQL and SQLite
Model.order("RANDOM()").first
# For MySQL
Model.order("RAND()").first
Related External Links:
Need to get a random record? Fortunately databases have built-in functions for this.
# For PostgreSQL and SQLite
Model.order("RANDOM()").first
# For MySQL
Model.order("RAND()").first
Related External Links:
Article Topic:Software Development - Ruby / Rails
Date:August 31, 2015
Want me to help develop your next Ruby-on-Rails project or application?
Contact Me