I can't find very good intros to specific callbacks in rails.
Basically I'm dealing with two models:
- Order
- Item, (nested in Order form)
I'm using the before_update model to do some basic math:
class Order < ActiveRecord::Base
accepts_nested_attributes_for :line_items
before_update :do_math
protected
def do_math
self.req_total = self.line_items.sum(:total_price)
end
req_total is the total value of the order, when a user updates the amounts I need to add up the total_price of the line_items. What am I doing wrong? My logic fails to read the newly submitted total_price.
Thanks!