2016-11-19 12 views
0

私のプロジェクトではマスター価格で商品を並べ替えることができません。 私はstandart spree installを使用します。こんにちは、並べ替え

がtaxons_controller.rbのshowメソッドの一部修正:PRYコンソールで、私は@products.reorder('').send(:descend_by_master_price)を書くとき

@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) 

を、私は次を得る:<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

関連する問題