如何在acts_as_taggable_on中生成标签云?

时间:2010-01-04 19:46:12

标签: tags tag-cloud acts-as-taggable-on-ster

我无法调试我收到错误的原因:

class VendorsController < ApplicationController
  def tag_cloud
    @tags = Vendor.tag_counts_on(:tags)
  end

我将此类设置为Taggable:

class Vendor < ActiveRecord::Base
  acts_as_taggable_on :tags, :competitors

我包含了TagsHelper:

module VendorsHelper
  include TagsHelper
end

这是我的观点:

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

这是我得到的错误:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.empty?

供应商的每个实例都至少有一个标记。

1 个答案:

答案 0 :(得分:5)

知道了,我需要在@tags = Vendor.tag_counts_on(:tags)中添加index controller