I have a model like so
class Post < ApplicationRecord
has_many :comments,
after_add: :soil,
after_remove: :soil,
dependent: :destroy
attr_accessor :soiled_associations
accepts_nested_attributes_for :comments, allow_destroy: true
def soil(record)
self.soiled_associations = [record]
end
end
When I add a new comment in the view it adds the object to my post.soiled_associations attribute (BTW soiled_associations is my attempt to name a custom method that does something similar to Rails's Dirty class, but for associations).
However, when I delete a comment in my view nothing gets added to the post.soiled_associations attribute.
What am I doing wrong? I suspect it is in something about how accepts_nested_attributes_for works (perhaps bypassing these callbacks) but can anybody shed some light on this?
Can't tell you what you are doing wrong since you haven't shown what you're doing. But there are only a few ways to do it: