Search code examples
ruby-on-railstagstag-cloudacts-as-taggable

Sort tag cloud alphabetically in acts_as_taggable_on_steroids


I got the acts_as_taggable_on_steroids plugin to work fine. The tag_cloud method in my view create and formats the cloud properly however the tags are listed in order of 'count desc'.

How to I present my tags in the cloud in alphabetical order?


Solution

  • Here is what I am doing on my site to sort my tags by name:

    <% tag_cloud Post.tag_counts.sort { |x, y| x.name <=> y.name }, %w(x-small small normal large x-large) do |tag, css_class| %>
      <%= link_to tag.name, tag_url( :tag => tag.name ), :class => css_class %>
    <% end %>