Callback for changed ActiveRecord attributes?

后端 未结 6 1983
一生所求
一生所求 2020-12-14 03:07

I am aware of ActiveRecord::Dirty and the related methods, but I don\'t see a means by which I can subscribe to an attribute changed event. Something like:

         


        
6条回答
  •  悲哀的现实
    2020-12-14 03:28

    The easiest way that I found:

    after_save :my_method, :if => Proc.new{ self.my_attribute_changed? }
    
    def my_method
      ... do stuff...
    end
    

提交回复
热议问题