class Account < ActiveRecord::Base
after_update :give_user_credit, :on => :update
def give_user_credit
credit = User.current_user.credit + 3.8
User.current_user.update_attribute(:credit, credit)
end
end
When I use this the server hangs and when I come back to the application after a full reboot my credit is in the £1000’s.
Whats going on here..
Thanks 😀
Looks to me like you are setting the
:give_user_credit callbackto run every time that the record is updated.But since the callback updates the record, it then triggers the callback again, which will continue on and on…