【问题标题】:Find all products with any tags in list在列表中查找所有带有任何标签的产品
【发布时间】:2017-02-21 05:06:15
【问题描述】:

在我的狂欢商店中,我需要在标签列表中找到任何具有一个或多个标签的产品。 spree 中的标签是使用acts-as-taggable-on gem 完成的。

我已经尝试过使用

Spree::Product.joins("spree_taggings").where("taggings.id IN (?)", list_of_tag_ids )

但它似乎不起作用。

如何通过标签查找产品?

【问题讨论】:

  • 能否请您也发布关联

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


【解决方案1】:

需要按 ID 搜索吗?如果您可以按名称搜索,则可以使用范围内的构建 .tagged_with

Spree::Product.tagged_with(["awesome", "cool"], :match_all => true)

文档:https://github.com/mbleigh/acts-as-taggable-on#finding-tagged-objects

如果确实需要按 ID 搜索,当然可以先获取它们。

ActsAsTaggableOn::Tag.where("id IN (?)", list_of_tag_ids).pluck(:name)

【讨论】:

  • 啊,tagged_with()。我忘记了。我得尽快测试一下。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-25
  • 1970-01-01
  • 2017-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多