The issue popped up in the function used by the main page to return three random testimonials (in random order) for presentation on the homepage. The RoR code for the function is:
number_to_return = 3
Testimonial.find(:all, :limit => number_to_return, :order => "RANDOM()")
The highlighted ActiveRecord call more or less translates into this SQL:
SELECT * FROM testimonials ORDER BY RANDOM() LIMIT 3
The SQL server is expected to return three (3) entries in random order. It works great in SQLite and PostgreSQL. It also works great in MySQL, except MySQL doesn't have RANDOM() but rather has a RAND() - which does the exact same thing.
However, I did not want to have to change the RoR code, which was already passing its unit tests. Besides doing so would cause the code to not work in the other databases, which define the RANDOM function. The quickest solution turns out to be to define a custom RANDOM function for MySQL!
MySQL statement to define RANDOM() as an alias for its native RAND()
CREATE FUNCTION random() RETURNS FLOAT NO SQL SQL SECURITY INVOKER RETURN rand();
(This SQL statement was originally posted at Selecting random in rails sqlite vs mysql by Jason Weathered, thank you Jason!).
And everything worked. I hope this will help you too.