rindex not working with objects from db model

I'm sorting a separate list that doesn't contain a certain user's
attribute, but trying to but that certain user's attribute on the
separate percentile.

test_scores = Testscore.find(:all, :conditions=> {...})

my_testscore = current_user.test_score
my_ts = Testscore.new(:score => my_testscore)

test_scores.push(ts)

sorted_ts = test_scores.sort {|x,y| x.score <=> y.score }

index_one = sorted_ts.index(my_ts)
# why doesn't this work?
index_two = sorted_ts.rindex(my_ts)

It finds index_one correctly, but index_two always equals index_one,
even if there are more than one object with a score of my_testscore.

Please help! Thanks.

I'm sorting a separate list that doesn't contain a certain user's
attribute, but trying to but that certain user's attribute on the
separate percentile.

test_scores = Testscore.find(:all, :conditions=> {...})

my_testscore = current_user.test_score
my_ts = Testscore.new(:score => my_testscore)

test_scores.push(ts)

sorted_ts = test_scores.sort {|x,y| x.score <=> y.score }

index_one = sorted_ts.index(my_ts)
# why doesn't this work?
index_two = sorted_ts.rindex(my_ts)

It finds index_one correctly, but index_two always equals index_one,
even if there are more than one object with a score of my_testscore.

ActiveRecord object compare base on their primary key so this is the
expected behaviour.
sorted_ts.rindex {|test_score| test_score.score == my_ts.score} might
be what you want.

Fred

Thanks. Sorry, but I'm getting an argument error now... it tells me I
should have 1 argument, not 0?

Frederick Cheung wrote:

Thanks. Sorry, but I'm getting an argument error now... it tells me I
should have 1 argument, not 0?

oops, looks like the block version is only available in 1.8.7.

Fred