Ruby on rails Rails:使用acts_as_taggable标记云

Ruby on rails Rails:使用acts_as_taggable标记云,ruby-on-rails,ruby,acts-as-taggable-on,Ruby On Rails,Ruby,Acts As Taggable On,我使用gem来获得我的pin的分类(标签),但是我不能生成一个合适的云标签来获得所有标签的列表(事实上我只有两个不同的标签) 在我的应用程序/controllers/pins_controller.rb中 def tagged if params[:tag].present? @pins = Pin.tagged_with(params[:tag]) else @pins = Pin.postall end end def tag_cloud Pi

我使用gem来获得我的pin的分类(标签),但是我不能生成一个合适的云标签来获得所有标签的列表(事实上我只有两个不同的标签)

在我的应用程序/controllers/pins_controller.rb中

def tagged
  if params[:tag].present? 
    @pins = Pin.tagged_with(params[:tag])
  else 
    @pins = Pin.postall
  end  
end


def tag_cloud
    Pin.find(:first).pins.tag_counts_on(:tags)
    @tags = Pin.tag_counts_on(:tags)
end
def index
    @pins = Pin.order(votes_count: :desc)
    @pin_count = Pin.count
  end
app/models/pin.rb

acts_as_taggable_on :tags
end
app/helpers/pin_helpers.rb

module PinsHelper
    include ActsAsTaggableOn::TagsHelper
end
在我的应用程序/views/pins/index.html.erb中

<% 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 %>
我做错了什么?我在维基上看到了《作为一颗宝石的行动》

编辑: app/controllers/pins_controller.rb

def tagged
  if params[:tag].present? 
    @pins = Pin.tagged_with(params[:tag])
  else 
    @pins = Pin.postall
  end  
end


def tag_cloud
    Pin.find(:first).pins.tag_counts_on(:tags)
    @tags = Pin.tag_counts_on(:tags)
end
def index
    @pins = Pin.order(votes_count: :desc)
    @pin_count = Pin.count
  end

您需要在
索引
方法中实际提取标签:

def index
  @pins = Pin.order(votes_count: :desc)
  @tags = Pin.tag_counts_on(:tags)
  @pin_count = Pin.count
end

你在pins\u controller.rb中的索引操作是什么样子的?你也可以从你的
tag\u cloud
方法中删除
Pin.find(:first).pins.tag\u counts(:tags)
,因为它不会被存储/返回到任何地方。我用我的Pin\u controller.rb索引编辑了我的问题