Advertisement
t_a_w

ActiveRecord force random shuffle

Apr 20th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.28 KB | None | 0 0
  1. Rails.application.eager_load!
  2. ObjectSpace.each_object(Class) do |cls|
  3.   if cls.ancestors[1..-1].include?(ActiveRecord::Base)
  4.     begin
  5.       cls.instance_eval do
  6.         default_scope { order('rand()') }
  7.       end
  8.     rescue
  9.       warn "Can't fix #{cls}"
  10.     end
  11.   end
  12. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement