我正在尝试使用acts_as_taggable实现一个标签云。我已经有了自己的标记模型,我希望能利用当前的代码,只使用acts_as_taggle作为云。例如,在我的控制台中,我可以这样做。
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“内连接
"tag\_items" ON "items"."id" = "tag\_items"."item\_id" WHERE "tag\_items"."tag\_id" = 1 => 534 我已经添加了acts_as_taggable gem,并且我有一个标记助手,它看起来像...
module TagsHelper
include ActsAsTaggableOn::TagsHelper
end我的控制器里有..。
class TagsController < ApplicationController
...
def tag_cloud
@tags = Tag.tag_counts_on(:tags)
end
end在我看来..and我有...
<% 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 %>我直接从github上的gem readme中摘录了这篇文章。我得到的错误是...
undefined method `count' for #<Tag:0xbfe5438>甚至不确定这是从哪里来的。感谢您的帮助。
发布于 2012-08-30 20:53:17
我最终通过修改这里的代码创建了我的标签云……
http://www.idolhands.com/ruby-on-rails/guides-tips-and-tutorials/creating-a-heatmap-or-tag-cloud-in-rails
这是我的代码。https://gist.github.com/3505320
希望这对某些人有帮助!
https://stackoverflow.com/questions/12102317
复制相似问题