Tag limit for acts as Taggable On

I am wondering how to limit the number of tags, the tag_cloud function is returned for this plugin. http://github.com/collectiveidea/acts-as-taggable-on

In addition, I would like to know how to order it so that it orders the highest score tags. Thus, the most popular are at the top.

I tried to do @tags = Post.tag_counts_on (: tags ,: limit => 5), but that didn't work.

Controller:

class PostController < ApplicationController def tag_cloud @tags = Post.tag_counts_on(:tags) end end 

View:

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

Thanks!

+4
source share
1 answer

Make sure you use the latest plugin from github. It works there, and it did not work in some earlier versions.

Then the top 5 highest counter will be:

 @tags = Post.tag_counts_on(:tags, :limit => 5, :order => "count desc") 
+6
source

Source: https://habr.com/ru/post/1310678/


All Articles