Find and sort by number of ocurrences of tag with Active Admin and act_as_taggable_on
Posted
by
nunopolonia
on Stack Overflow
See other posts from Stack Overflow
or by nunopolonia
Published on 2012-10-10T15:33:32Z
Indexed on
2012/10/10
15:36 UTC
Read the original article
Hit count: 236
I'm using act_as_taggable_on and Active Admin on a Rails project. In that project there are Posts and each Post has Tags. I want to show a list of Tags in Active Admin and the number of ocurrences of each one.
The way I found to do this was:
index do
column :name
column :ocurrences do |tag|
ocurrences = Post.tag_counts.find(tag.id).count
end
default_actions
end
Which will search the Tag List every time for every Post, which performance wise looks really bad.
I would also like to be able to sort the tags by ocurrence. Any idea of how I can do it?
© Stack Overflow or respective owner