関連付けられたモデルでモデルをクエリする必要があります。
擬似コード: @drinks = Drink.where(drink.ingredients ARE IN Cabinet.ingredients)
ドリンクモデル
class Drink < ActiveRecord::Base
attr_accessible :name
has_many :recipe_steps, :dependent => :destroy
has_many :ingredients, through: :recipe_steps
end
成分モデル
class Ingredient < ActiveRecord::Base
attr_accessible :name
has_many :recipe_steps
has_many :drinks, through: :recipe_steps
has_many :cabinet_ingredients
belongs_to :cabinet
end
ユーザーモデル
class User < ActiveRecord::Base
has_one :cabinet
end
編集:示唆されたように、私は試しました
Drink.joins(ingredients: :cabinet_ingredients)
ただし、キャビネットおよび/または複数のユーザーから2つの材料を含む1つの飲み物を飲むと、同じ飲み物の複数のレコードが返されます。
飲み物のレコードを 1 つだけ返却する必要があります。さらに、すべての成分がキャビネット内で一致している場合にのみ、飲み物を返却する必要があります。