Profile.featured bug
Reported by Sazima | July 15th, 2008 @ 11:48 AM
Hey,
Profile.featured produces an error in the SQL query when there are only 0 or 1 users that meet the find_options because of the use of rand(). Also, you shouldn't subtract 1 from the count, since by using rand with an integer greater than 1, you will already get a value greater than or equal to 0 and less than the argument given to rand.
def self.featured
find_options = {
:include => :user,
:conditions => ["is_active = ? and about_me IS NOT NULL and user_id is not null", true],
}
find(:first, find_options.merge(:offset => rand( count(find_options) - 1)))
end
ERROR:
SELECT * FROM `profiles` WHERE (is_active = 1 and about_me IS NOT NULL and user_id is not null) LIMIT 0.969211788092315, 1
FIX:
find(:first, find_options.merge(:offset => rand(count(find_options)).floor))
SUGGESTION:
"before_filter :check_featured" is called throughout the application, even where it is not needed. Wouldn't be the case to move it to home or profiles?
Cheers, Sazima
Comments and changes to this ticket
-
Steven Bristol July 21st, 2008 @ 08:05 AM
- → State changed from new to resolved
- → Assigned user changed from to Steven Bristol
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
