2010-01-04 77 views
3

我不能調試爲什麼我收到一個錯誤:如何在acts_as_taggable_on中生成標籤雲?

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

我設置類爲可加標籤:

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? 

供應商的每個實例都有至少一個標籤。

回答

5

明白了,我需要補充:@tags = Vendor.tag_counts_on(:tags)index controller

+0

謝謝,我被困在這! – 2010-10-06 23:58:32