0

我有一个模型,它指定了一个 before destroy 回调。就像是:

Class User < ActiveRecord::Base
  before_destroy :do_destroy
  acts_as_destroyable

  private
  def do_destroy
    puts "A"
  end
end

module ActsAsDestroyable
  def self.included(base)
    base.send(:extend, ActsMethods)
  end

  module ActsMethods
    def acts_as_destroyable(options = {})
      self.send(:include, InstanceMethods)
    end

    module InstanceMethods
      def do_something
        puts "A0"
      end

      def self.included(base)
        base.before_destroy :do_something
      end
    end
  end
end

现在,由于 Destroyable 模块与用户的关联工作,它需要在“do_destroy”回调之前执行其“do_domething”方法。任何想法如何将它移到回调队列中?

4

0 回答 0