【问题标题】:Limiting the Amount of Tags for Acts as Taggable On限制作为可标记的行为的标记数量
【发布时间】:2011-02-23 00:11:57
【问题描述】:

我想知道如何限制标签的数量,这个插件的 tag_cloud 函数返回。 http://github.com/collectiveidea/acts-as-taggable-on

另外,我想知道如何订购它,以便它按最高计数订购标签。所以最受欢迎的在顶部。

我尝试过 @tags = Post.tag_counts_on(:tags, :limit => 5) 但没有奏效。

控制器:

class PostController < ApplicationController
  def tag_cloud
     @tags = Post.tag_counts_on(:tags)
  end
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 %>

谢谢!

【问题讨论】:

    标签: ruby-on-rails plugins tags ruby-on-rails-plugins


    【解决方案1】:

    确保您使用的是来自 github 的最新插件版本。它确实在那里工作,但在某些早期版本中不起作用。

    那么前 5 名将是:

    @tags = Post.tag_counts_on(:tags, :limit => 5, :order => "count desc") 
    

    【讨论】:

    • 感谢 voyta,我必须获得集体创意的最新插件才能正常工作。似乎 mbleigh 的版本不适用于这些命令。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多