Limiting the Amount of Tags for Acts as Taggable On

Posted by bob on Stack Overflow See other posts from Stack Overflow or by bob
Published on 2010-05-23T20:07:00Z Indexed on 2010/05/23 20:10 UTC
Read the original article Hit count: 372

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

Also, I would like to know how to order it so that it orders the tags by the highest count. So the most popular are at the top.

I tried to do @tags = Post.tag_counts_on(:tags, :limit => 5) but that did not 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!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about plugins