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     else       self.balance = income     end   end

  def update_next_product     next_product.update_attributes({}) unless next_product   end

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

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

  def actual_index     Product.find(:all).index(self)   end end

am I missing something? thanks

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 ?

Fred

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