Module: Carter::ActiveRecord::Cartable

Defined in:
lib/carter/cartable.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#acts_as_cartable(options = {}) ⇒ Object

Options

acts_as_cartable :name => "name_column", :price => "price_column", :unique => true / false
:unique => true # this allows only one item of this type in the cart.


8
9
10
11
12
13
14
15
16
17
# File 'lib/carter/cartable.rb', line 8

def acts_as_cartable(options = {})
  configuration = { :name => "name", :price => "price", :unique => false }
  configuration.update(options) if options.is_a?(Hash)
  @cartable_configuration = configuration
  has_many :cart_items, :as => :cartable
  has_many :carts, :through => :cart_items
  register_cartable(self)
  include InstanceMethods
  true
end

#cartable_configurationObject



19
20
21
# File 'lib/carter/cartable.rb', line 19

def cartable_configuration
  @cartable_configuration ||= {}
end