Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I generate a tag cloud in acts_as_taggable_on?

I can't debug why I am getting an error:

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 the TagsHelper:

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 that 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 instance of Vendor has at least one Tag.

like image 498
Satchel Avatar asked Feb 02 '26 10:02

Satchel


1 Answers

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

like image 107
Satchel Avatar answered Feb 04 '26 00:02

Satchel