DEPRECATION WARNING: Dangerous query method: Random Record in ActiveRecord >= 5.2

If you want to continue using order by random() then just declare it safe by wrapping it in Arel.sql like the deprecation warning suggests: Model.order(Arel.sql(‘random()’)).first # PostgreSQL Model.order(Arel.sql(‘rand()’)).first # MySQL There are lots of ways of selecting a random row and they all have advantages and disadvantages but there are times when you absolutely must … Read more