I have a model with a callback that runs after_update:
after_update :set_state
protected
def set_state
if self.valid?
self.state = 'complete'
else
self.state = 'in_progress'
end
end
But it doesn’t actually save those values, why not? Regardless of if the model is valid or not it won’t even write anything, even if i remove the if self.valid? condition, I can’t seem to save the state.
Um, this might sound dumb, do I need to run save on it?
update
Actually, I can’t run save there because it results in an infinite loop. [sighs]
after_updateis run after update, so also after save. You can useupdate_attributeto save this value, or just callsave(I’m not sure if there don’t be any recurence). Eventualy you can assign it inbefore_update(list of availble options is here). On the other side invalid object will not be saved anyway, so why you want to assign here thestate?