如何在acts_as_taggable_on中生成标签云?

Tim*_* T. 3 tags tag-cloud acts-as-taggable-on-ster

我无法调试为什么我收到错误:

class VendorsController < ApplicationController
  def tag_cloud
    @tags = Vendor.tag_counts_on(:tags)
  end
Run Code Online (Sandbox Code Playgroud)

我把这个类设置为Taggable:

class Vendor < ActiveRecord::Base
  acts_as_taggable_on :tags, :competitors
Run Code Online (Sandbox Code Playgroud)

我包含了TagsHelper:

module VendorsHelper
  include TagsHelper
end
Run Code Online (Sandbox Code Playgroud)

这在我看来:

 <% 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 %>
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

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?
Run Code Online (Sandbox Code Playgroud)

供应商的每个实例至少有一个标签.

Tim*_* T. 5

得到它,我需要添加:@tags = Vendor.tag_counts_on(:tags)index controller.