I was using the following method in my Rails 4 app to get random records in a model:
Model.order('RANDOM()').limit(5)
This broke after upgrading to Rails 4.0.2. It's always getting the most recent records. Any ideas why?
I was using the following method in my Rails 4 app to get random records in a model:
Model.order('RANDOM()').limit(5)
This broke after upgrading to Rails 4.0.2. It's always getting the most recent records. Any ideas why?
You either need to remove the default scope from your model or call it like this:
Model.unscoped.order('RANDOM()').limit(5)
Simply use Model.all.sample(5)