class Post < ActiveRecord::Base
has_many :comments
after_save :do_something, if: -> (post) { [ something like post.comments.count.changed? ] }
end
class Comment < ActiveRecord::Base
belongs_to :post
end
如果评论数量发生变化,如何执行do_something?
如果我通过示例检测到3个以上的更改,我想执行do_something:添加2个注释,删除2个。