Question

I am trying to implement a tag cloud using acts_as_taggable. I already have my own tag model in place, and am hoping to piggy back on the current code, and just use acts_as_taggle for the cloud. So for instance in my console I can do...

1.9.3p194 :005 > t=Tag.first
Tag Load (1.4ms)  SELECT "tags".* FROM "tags" LIMIT 1
=> #<Tag id: 1, path: "corporation", friendly_name: "Corporation", popular: false,  
hot_topic: false> 
1.9.3p194 :006 > t.items.count

(11.6ms) SELECT DISTINCT COUNT(DISTINCT "items"."id") FROM "items" INNER JOIN
"tag_items" ON "items"."id" = "tag_items"."item_id" WHERE "tag_items"."tag_id" = 1 => 534

I have added the acts_as_taggable gem, and I have a tags helper that looks like...

module TagsHelper
  include ActsAsTaggableOn::TagsHelper
end

In my controller I have...

class TagsController < ApplicationController
...

  def tag_cloud
    @tags = Tag.tag_counts_on(:tags)
  end
end

..and in my view I have...

<% 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 %>

I pulled this pretty much straight from gem readme on github. The error I am getting is...

undefined method `count' for #<Tag:0xbfe5438>

Not exactly sure where this is even coming from. Any help appreciated.

Was it helpful?

Solution

I ended up creating my tag cloud with a modification of code from here...

http://www.idolhands.com/ruby-on-rails/guides-tips-and-tutorials/creating-a-heatmap-or-tag-cloud-in-rails

Here is my code... https://gist.github.com/3505320

Hope this helps somebody out!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top