Module: ActiveRecord::Acts::ShoppingCart::ClassMethods

Defined in:
lib/active_record/acts/shopping_cart.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_shopping_cartObject

Alias for:

acts_as_shopping_cart_using :shopping_cart_item


30
31
32
# File 'lib/active_record/acts/shopping_cart.rb', line 30

def acts_as_shopping_cart
  acts_as_shopping_cart_using :shopping_cart_item
end

#acts_as_shopping_cart_using(item_class) ⇒ Object

Prepares the class to act as a cart.

Receives as a parameter the name of the class that will hold the items

Example:

acts_as_shopping_cart :cart_item


19
20
21
22
23
# File 'lib/active_record/acts/shopping_cart.rb', line 19

def acts_as_shopping_cart_using(item_class)
  send :include, ActiveRecord::Acts::ShoppingCart::Collection
  send :include, ActiveRecord::Acts::ShoppingCart::Item
  has_many :shopping_cart_items, class_name: item_class.to_s.classify, as: :owner, dependent: :destroy
end