params[]
配列内のすべてのアイテムに一致する ActiveRecord クエリが必要です。
私の現在の方法では、「MATCH ALL」ではなく、タグの検索に基づいて結果が得られます
class Product < ActiveRecord::Base
has_many :tags
def self.filter_by_params(params)
scoped = self.scoped
scoped = scoped.includes(:tags).where(:tags => {:id => params[:t]}) if params[:t]
scoped
end
end
以下のように書こうとしましたが、結果が得られません。誰かが私を正しい方向に向けることができますか? 言い方はあります" AND "
か?
def self.filter_by_params(params)
scoped = self.scoped.includes(:tags)
params[:t].each do |t|
scoped = scoped.where(:tags => {:id => t})
end
scoped
end