【问题标题】:Tag cloud of only specific posts in rails仅包含 Rails 中特定帖子的标签云
【发布时间】:2011-08-09 10:33:35
【问题描述】:

您好,我在我的 rails 应用 2.3.11 中使用acts_as_taggable。

我有模型用户,他可以发布具有关联标签的帖子。 所以我使用喜欢

@tags = User.find(:first).posts.tag_counts

获取将使用 tag_cloud 显示的标签

现在的问题是,我们有一些功能可以根据帖子类型的某些条件删除用户的一些帖子,现在我如何才能只获取这些帖子的标签。 我想要的帖子保留在 @posts 中。但是如何使用相同的..

请给点建议

【问题讨论】:

    标签: ruby-on-rails acts-as-taggable


    【解决方案1】:

    在帖子中定义一个范围,该范围根据帖子类型定义条件。因为,你没有提到确切的标准..

    class Post < ActiveRecord::Base
      scope :specific_type, <?> #fill in with conditions for type of post
    end
    
    User.find(:first).posts.specific_type.tag_counts
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-02
      • 1970-01-01
      • 2017-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多