I found a solution that seems to work:
class Invoice < ActiveRecord::Base
attr_accessible :job_name, :items_attributes, :tax1, :tax2, :subtotal
before_save :calculate_totals
has_many :items, :dependent => :destroy
accepts_nested_attributes_for :items, allow_destroy: true
private
def calculate_totals
self.subtotal = 0
self.items.each do |i|
unless i.marked_for_destruction?
self.subtotal += (i.quantity * i.cost_per)
end
end
end
The key is the method marked_for_destruction? In this case I was checking for items that weren't marked for destroy. Here's the link to the rails api that explains it: http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
Thanks Steve