2016-11-19 52 views
0

以主價格對產品進行排序不能在我的項目中使用。 我使用標準大禮包安裝。Sorting in spree

taxons_controller.rb顯示方法的

修改部分:

@searcher = build_searcher(params.merge(taxon: @taxon.id, include_images: true)) 
@products = @searcher.retrieve_products 
binding.pry 
@products = @products.reorder('').send(:descend_by_master_price) 

當撬控制檯我寫@products.reorder('').send(:descend_by_master_price),我得到以下幾點:<Module:0x007f1e0048daa8>:0x3f8f041276b8>

但是,如果我寫Product.all.reorder('').send(:descend_by_master_price)一切工作正常。

而且在@products.reorder('').send(:descend_by_master_price).last情況下,我得到的errror:

ActiveRecord::StatementInvalid: PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list 
LINE 1: ...UB' AND "spree_products"."id" IN (5, 1) ORDER BY "spree_pri... 

所以,問題是DISTINCT ...

任何人都可以幫助嗎?

回答

3

您需要在select子句中具有ORDER BY字段。 嘗試使用,

@products.select('spree_products.*, spree_prices.amount').reorder('').send(:descend_by_master_price) 
+0

哦,這樣一個簡單的解決方案!謝謝你! – nuT707