当模型B上的对象发生更改时,如何在模型A上运行回调

时间:2013-04-06 22:51:37

标签: ruby-on-rails-3

如果我有

Class A 
 has_many :b

 after_save :run_method

 protected
 def update_expiration
     //
 end

Class B 
 belongs_to :a

当B中的对象更新时,我需要在A上运行更新以更改到期日期。问题是A上的方法受到保护,所以我无法通过B内部的回调来调用它。我只想:在对B进行更改时运行update_expiration。

1 个答案:

答案 0 :(得分:0)

class A 
  has_many :b

  after_save :run_method
  B.after_save :update_expiration

  protected

  def update_expiration
      # ...
  end
end
相关问题