> I have two models, Post and Rate. You can rate each post with "good" or
> "bad".
> I would like to create a named_scope to get the best posts.
> How can I do that?
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
--
Specialization is for insects. -RAH | Have Pun, Will Babble! -me
Programming Blog: http://codosaur.us | Work: http://davearonson.com
Leadership Blog: http://dare2xl.com | Play: http://davearonson.net
Sorry I haven't been very clear.
The model Rate has a column kind where it is stored "good" or "bad".
What I want is to count all the "good" and "bast" rates.
--
Posted via http://www.ruby-forum.com/.
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.