ruby on rails - How to detect if number of associated objects change? -
class post < activerecord::base has_many :comments after_save :do_something, if: -> (post) { [ post.comments.count.changed? ] } end class comment < activerecord::base belongs_to :post end
how execute do_something if number of comments alter ?
i want execute do_something if observe more 3 changes illustration : 2 comments added, 2 deleted.
ruby-on-rails activerecord
No comments:
Post a Comment