0

我正在尝试在我的控制器中使用它基于用户微帖子(显然该用户的每个标签的计数)创建标签云

          @tags = @user.microposts.tag_counts_on(:tags)

这在我看来

         <% tag_cloud @tags, %w[xxs xs s m l xl xxl] do  |tag, css_class|  %>
         <%= link_to tag, questions_by_tag_user_path(@user, tag: tag.name), class: css_class %>
         <% end %>

问题是,经过反复检查,这将返回标签云,其大小基于基于所有微帖子的标签计数,而不仅仅是@user 的标签云。

我不明白为什么会这样,并且不推荐使用文档:

        User.find(:first).posts.tag_counts_on(:tags)

有什么想法吗?

4

1 回答 1

0

tag_counts_on如果您在 Posts 范围内调用,这将起作用:

Post.where(user_id: 1).tag_counts_on(:tag)
于 2015-06-19T11:07:03.073 回答