как мне создать облако тегов в act_as_taggable_on?
-
18-09-2019 - |
Вопрос
Я не могу отладить, почему я получаю сообщение об ошибке:
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
.
Не связан с StackOverflow