acts_as_taggable_on에서 태그 클라우드를 어떻게 생성합니까?
-
18-09-2019 - |
문제
왜 오류가 발생하는지 디버깅 할 수 없습니다.
class VendorsController < ApplicationController
def tag_cloud
@tags = Vendor.tag_counts_on(:tags)
end
이 수업을 taggable로 설정했습니다.
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?
공급 업체의 각 인스턴스에는 하나 이상의 태그가 있습니다.
해결책
그것을 추가해야했습니다. @tags = Vendor.tag_counts_on(:tags)
에서 index controller
.
제휴하지 않습니다 StackOverflow