Как создать облако тегов в acts_as_taggable_on? - PullRequest
3 голосов
/ 04 января 2010

Я не могу отладить, почему я получаю ошибку:

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

Я установил этот класс как Taggable:

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

Я включаю TagHelper:

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 Ответ

5 голосов
/ 04 января 2010

Понял, мне нужно было добавить: @tags = Vendor.tag_counts_on(:tags) в index controller.

...