親列の 1 つの値に基づいて、子レコードの配列をスコープしようとしています。「バンドル」カテゴリの商品に属するすべての ShoppingCartItems を見つけようとしています。
act_as_shopping_cart_gem を使用しようとしています
私のモデル。
ユーザー.rb
class User < ActiveRecord::Base
has_many :shopping_carts, dependent: :destroy
end
ShoppingCart.rb
class ShoppingCart < ActiveRecord::Base
acts_as_shopping_cart_using :shopping_cart_item
belongs_to :user
has_many :shopping_cart_items, dependent: :destroy
has_many :products, through: :shopping_cart_items
end
Product.rb
class Product < ActiveRecord::Base
has_many :shopping_cart_items, dependent: :destroy
end
ShoppingCartItem.rb
class ShoppingCartItem < ActiveRecord::Base
belongs_to :product, dependent: :destroy
scope :bundles, -> {
joins(:product).where('products.category = ?', 'Bundles') unless category.blank?
}
end
このエラーが発生しています:
> undefined local variable or method `category' for
> #<Class:0x007fc0f40310d0>