Search code examples
ruby-on-railspaper-trail-gem

Rails paper_trail not saving data to version_associations table


I'm sort of new to Rails and I'm kind of lost with this. I can't figure out what is happening or what can be wrong. I read and re-read the paper_trail manual on github and my code seems to be correct. Also read other issues in stackoverflow but nothing covers what is happening here. I installed the paper_trail gem and I need to save versions of a parent model when I change a child model, but nothing gets saved on the version_associations table (I did what says here https://github.com/airblade/paper_trail#4b-associations). A mirth can have many configs, and a config belongs to a Mirth. When anything is altered in a config, I want it to reflect on the Mirth versioning. What I'm I doing wrong?

Here is my code. Do you need anything else?

config.rb:

class Config < ApplicationRecord

 belongs_to :mirth
 has_paper_trail

end

mirth.rb:

class Mirth < ApplicationRecord

 has_many :configs, :inverse_of => :mirth, dependent: :destroy
 accepts_nested_attributes_for :configs, :allow_destroy => true, :reject_if => :all_blank

 has_paper_trail

end

Solution

  • Per the comments, setting PaperTrail.config.track_associations = true fixed the issue. See documentation section 4.b.