Model looks like
class Campaign < ActiveRecord::Base
before_update :delete_triggers
def delete_triggers
Trigger.where(campaign_id: id).delete_all
end
end
and in the controller I do
Campaign.find(params[:campaignId]).update(campaign_params)
where campaign_params just grabs the body and does some cleanup. delete_triggers never gets called though. There is no filter (there will be, but I removed it since the method wasn't firing. It didn't make a difference). In order to sanity check, I added to the model
before_save :check_dirty
def check_dirty
pp changed?
end
which prints true as expected.
What would cause before_update to not trigger on a call to .update, where before_save does? Obviously, I could just use before_save and add some filtering logic in the callback, but that's hacky when there's a hook made for this purpose.
(There are other questions similar to this, but not the same. One has a syntax error in a proc, and I'm not using a proc; and the other is a bad filter, which I removed specifically to avoid that possibility and am still getting the issue)