Showing only the most popular tags in the act_as_taggable_on tag cloud

Acts-as-taggable works fine and that’s it, but I was wondering if there is a way to limit the tag cloud to only the most popular tags? Right, it doesn't seem to be ordering my cloud in the order in which the tags were created.

But it makes sense to have a tag cloud of only the most popular tags.

My controller has:

  def styles_tag_cloud
     @tags = Tattoo.tag_counts_on(:styles).limit(40)
  end

and my opinion has:

<% tag_cloud(styles_tag_cloud, %w(css1 css2 css3 css4)) do |tag, css_class| %>
  <%= link_to tag.name, { :action => :tagged, :controller =>:index, :id => tag.name }, :class => css_class %>
<% end %>

But all this displays the first 40 tags created, and then the size of each tag according to how many times it was used

+5
source share
2 answers

MyModel.tag_counts_on(:tags), , count count ( ), , .limit(my_magic_number) .

, 10 Post, - :

@tag_counts = Post.tag_counts_on(:tags).limit(10)

, , @tags count, .

EDIT: ( )... ( ) , : Post.tag_counts_on(:tags).order('count desc').limit(however_many_you_want)

+7

, , ():

  def styles_tag_cloud
     @tags = Tattoo.tag_counts_on(:styles).limit(40)
  end

. !

+1

All Articles