I have a model that has an amount
and I'm tracking to see if this amount is changed with a Model.amount_changed?
with a before_save
which works fine but when I check to see amount_was
and amount_change?
it only returns the updated amount not the previous amount. And all this is happening before it is save. It knows when the attribute is changed but it will not return the old value.
Ideas?
class Reservation < ActiveRecord::Base
before_save :status_amount, :if => :status_amount_changed
def status_amount_changed
if self.amount_changed? && !self.new_record?
true
else
false
end
end
def status_amount
title = "Changed Amount"
description = "to #{self.amount_was} changed to #{self.amount} units"
create_reservation_event(title, description)
end
def create_reservation_event(title, description)
Event.create(:reservation => self, :sharedorder => self.sharedorder, :title => title, :description => description, :retailer => self.retailer )
end
end