Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Spree抓取分类单元和儿童分类单元的所有产品_Ruby On Rails_Spree - Fatal编程技术网

Ruby on rails Spree抓取分类单元和儿童分类单元的所有产品

Ruby on rails Spree抓取分类单元和儿童分类单元的所有产品,ruby-on-rails,spree,Ruby On Rails,Spree,我主要想从一个角度来把握以下几点: 当前分类群的所有产品,然后是分类群子女的所有产品。最好的方法是什么?已经有方法了吗?如果您只需要搜索一个级别的儿童,那么@PinnyM的答案就可以了,但是如果您想找到某个分类下的所有产品,您可以这样使用: taxon_products = current_taxon.products children_products = current_taxon.children.includes(:products).map(&:products).

我主要想从一个角度来把握以下几点:


当前分类群的所有产品,然后是分类群子女的所有产品。最好的方法是什么?已经有方法了吗?

如果您只需要搜索一个级别的儿童,那么@PinnyM的答案就可以了,但是如果您想找到某个分类下的所有产品,您可以这样使用:

taxon_products = current_taxon.products
children_products = current_taxon.children.includes(:products).map(&:products).
                                  flatten.compact.uniq
children_products = Spree::Product.in_taxon(current_taxon)

这应该在API文档中。