0

我想搜索一个产品,并从搜索结果中获取所有产品的所有类别,以创建一个过滤器界面,如 github(侧边栏中的“语言”菜单)。

@products = Product.product_search(params[:q])
@categories = ?

我想列出 @products 数组中产品的所有类别。

知道什么是最好的方法吗?

4

1 回答 1

1

我认为这应该可以解决问题。

@categories = @products.map(&:category).compact.uniq
于 2013-02-03T16:05:49.937 回答