查找除以下内容之外的热门标签

时间:2016-04-26 09:45:50

标签: ruby-on-rails ruby select hash except

我会找到前5个使用过的标签,同时排除那些带有某些名称的标签。我仍然希望返回5,而不仅仅是从哈希中删除元素。没有例外,代码工作正常:

def self.trending
  Tag.select("tags.id, tags.name,count(taggings.tag_id) as count").joins(:taggings).group("taggings.tag_id, tags.id, tags.name").order("count DESC").limit(5)
end

我可以使用我不想要的名称创建一个数组,除了那些来自select的名字吗?这不起作用。

def self.trending
  exclude = ["boring", "notworthy"]
  Tag.select("tags.id, tags.name,count(taggings.tag_id) as count").except(name: exclude).joins(:taggings).group("taggings.tag_id, tags.id, tags.name").order("count DESC").limit(5)
end

0 个答案:

没有答案