When updating my User
model, I have a callback which updates the credit
field:
class User < ActiveRecord::Base
around_update :adjust_credit
...
def adjust_credit
...
yield
...
puts "LEAVING: credit was #{self.credit}"
new_credit = self.credit - User.average_active
puts "new credit = #{new_credit}"
success = self.update_attribute :credit, new_credit
puts "AFTER SAVE CREDIT: #{User.find(self.id).credit}"
puts "Successful? #{success}"
end
end
For some reason, credit
doesn't update, as verified by the console log:
#console log
LEAVING: credit was 40
new credit = -25
AFTER SAVE CREDIT: 40
Successful? true