Problem with named_scope using a count

First you need to define "best". What is the overall rating for each
post? Good minus bad? Total good and ignore the bad? Something more
complex? How many "best" do you want?

Once you've defined that, you can figure out how to do it
programmatically for each post. Offhand I'd say this might wind up
being too slow to do on the fly for all posts, so as to find the top.
Premature optimization is the root of all evil, but still I'd give
SOME thought to how to stash a post's overall rating, especially in a
way that will make it trivial to retrieve the top N "best" posts (or
"worst" for that matter). Further thoughts if you like....

-Dave

Dave Aronson wrote:

Maybe adding 2 integer columns to your Posts table to count the hits?

When somebody rates the Post you just add 1 to whichever column you
need. Then it would be a simple matter of sorting your posts in
ascending/descending sequence by the column you want to work with.

I would add indexes by the columns to make it work faster.

pepe wrote:

Maybe adding 2 integer columns to your Posts table to count the hits?

When somebody rates the Post you just add 1 to whichever column you
need. Then it would be a simple matter of sorting your posts in
ascending/descending sequence by the column you want to work with.

I would add indexes by the columns to make it work faster.

Good idea

That's pretty much what I had in mind for stashing. There is some
merit to still having a separate Rate model, storing *who* rated each
Post as good or bad (and maybe when?), to prevent ballot-stuffing and
let them change it later. However, I would be tempted to call it
Rating, since the noun Rate is how often something happens, not an
opinon.

-Dave

That's pretty much what I had in mind for stashing. There is some
merit to still having a separate Rate model, storing *who* rated each
Post as good or bad (and maybe when?), to prevent ballot-stuffing and
let them change it later. However, I would be tempted to call it
Rating, since the noun Rate is how often something happens, not an
opinon.

I would agree with your naming of the Rating model. About the ballot-
stuffing you would have to come up with logic to stop it. First you
would need to be able to uniquely identify a user/visitor/rater and
then figure out some logic to stop the ballot-stuffing depending on
your needs (one vote only, or one vote per day/hour/week, etc).