Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ActiveRecord 有很多回调,包括一个 after_commit 回调,这很好,但对于观察者来说,似乎没有办法让它只在更新时有效,而不是在创建时有效,反之亦然。
有没有办法获得这种行为?就像是...
def after_commit return unless self.was_just_updated # ..... end
答案...
def after_commit return if created_at == updated_at # ..... end