ruby - Rails model set boolean when record updated -
i have model want set boolean false whenever changed. taht way can reprocess later make sure related records date. i've tried few things, keep getting myself loop.
/app/model/contest.rb
class contest < activerecord::base has_many :results, dependent: :destroy after_update :set_contest_not_updated def set_contest_not_updated self.contest_updated=false self.save end def set_contest_updated self.update_column(:contest_updated_at, time.now) self.update_column(:contesy_updated, true) end
expected action:
contest.update_atrributes(flag_that_effects_scoring: true)
i expect above run, contest.contest_updated boolean set false , set true when contest.set_contest_updated() method run.
of course calling save
in after_update
callback loop. keeps saving on , on again until end of time.
however, before_update
should job done.
ps: don't call save
on *_save
, *_update
callbacks. loops.
before_update :set_contest_not_updated def set_contest_not_updated self.contest_updated = false end
Comments
Post a Comment