#10 ✓resolved
Sazima

Profile.featured bug

Reported by Sazima | July 15th, 2008 @ 12:00 PM

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

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket

Pages