Recursive updates

Hi everybody, I'm trying to do some kind of recursive update that
looks like this:

Products list
Quantity Price Balance
10 5 10
5 5 15

as you can see, balance is like the current quantity + previous
balnce, the problem is when i update a product, because the next
product must be updated too, and so on. so far i tryed this:

class Product < ActiveRecord::Base
  after_update :update_next_product
  before_update :prepare_product

  def prepare_product
    unless actual_index == 0
      self.balance = previous_product.balance + income
      self.balance = income

  def update_next_product
    next_product.update_attributes({}) unless next_product

  def next_product
     Product.find(:all)[actual_index+1] unless actual_index ==
(entries.size - 1)

  def previous_product
    Product.find(:all)[actual_index-1] unless actual_index == 0

  def actual_index

am I missing something?

I'm not sure entirely what you're doing but you're doing the update
unless next_product: surely that should be if next_product ?


Thank you very much, i'm feeling kind a dumb right now, hehe.