Вопрос

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

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?

Каждый экземпляр Vendor имеет хотя бы один тег.

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top