Find and sort by number of ocurrences of tag with Active Admin and act_as_taggable_on
- by nunopolonia
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?