How can I create a tag cloud in act_as_taggable_on?

I cannot debug why I get the error message:

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

I set this class as Taggable:

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

I include tagHelper:

module VendorsHelper
  include TagsHelper
end

This is in my view:

 <% 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 %>

This is the error I get:

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?

Each Vendor instance has at least one tag.

+3
source share
1 answer

Got it, I needed to add: @tags = Vendor.tag_counts_on(:tags)c index controller.

+5
source

Source: https://habr.com/ru/post/1727271/


All Articles