如何在acts_as_taggable_on中生成标签云?
我无法调试为什么会出现错误:
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?
供应商的每个实例都至少有一个标签。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
明白了,我需要在
索引控制器
中添加:@tags = Vendor.tag_counts_on(:tags)
。Got it, I needed to add:
@tags = Vendor.tag_counts_on(:tags)
in theindex controller
.