我正在尝试根据其中一个父列中的值来确定子记录数组的范围。我正在尝试查找属于“捆绑”类别的产品的所有 ShoppingCartItems。
我正在尝试使用acts_as_shopping_cart_gem
我的模特。
用户.rb
class User < ActiveRecord::Base
has_many :shopping_carts, dependent: :destroy
end
购物车.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
产品.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>