Skip to content

Instantly share code, notes, and snippets.

View pklingem's full-sized avatar

Patrick Klingemann pklingem

View GitHub Profile
class AddCountOnHandToVariantsAndProducts < ActiveRecord::Migration
def self.up
add_column :variants, :count_on_hand, :integer, :default => 0, :null => false
add_column :products, :count_on_hand, :integer, :default => 0, :null => false
Variant.class_eval do
def on_hand=(new_level)
delta_units = new_level.to_i - on_hand.to_i
# increase Inventory when positive delta
module ActiveRecord
module NestedAttributes #:nodoc:
module ClassMethods
# Defines an attributes writer for the specified association(s). If you
# are using <tt>attr_protected</tt> or <tt>attr_accessible</tt>, then you
# will need to add the attribute writer to the allowed list.
#
# Supported options:
# [:allow_destroy]
# If true, destroys any members from the attributes hash with a