我正在使用回调来停止销毁操作,而是想设置 :archived_at 字段。问题是,我的 before_destroy 中的“return false”会导致回滚,从而消除我的更新。解决方案?
class MarkArchived
def before_destroy(model)
update_attribute(:archived_at, Time.now) and return false
end
end
class User < ActiveRecord::Base
before_destroy MarkArchived
end
class Account < ActiveRecord::Base
before_destroy MarkArchived
end