有没有办法强制首先触发“before_destroy”回调?

时间:2012-10-31 06:44:57

标签: ruby-on-rails ruby activerecord

我有一个模型,它指定了一个之前的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”方法。任何想法如何将其向上移动回调队列?

0 个答案:

没有答案