Hi, I'm new to rails and I'm trying to find the top ten posted url in
my mysql db... so let's say my db name is links and each item has two
fields (userid and url)... I want to find the top 10 posted url by
count... how can I do that? I know I have to use the find() method but
I'm having trouble with count()...
Hi, I'm new to rails and I'm trying to find the top ten posted url in
my mysql db... so let's say my db name is links and each item has two
fields (userid and url)... I want to find the top 10 posted url by
count... how can I do that? I know I have to use the find() method but
I'm having trouble with count()...
Assuming you are using a sql database, the non-rails way to do this is:
select url, count(url)
from my_table
group by url
limit 10
Using Active Record you need to look atthe :group and :limit attributes.
Sketchy, a couple of things, one calling find() on a model object
expects to be able to return to you a set of model objects. A
count (or sum, ...) aren't generally in your model so its
hard to coerce the select into a model form.
Second, you have to tell the database sometime to
actually do some counting. The following would work if you
have in your Links table some number column called
"counter"