Use a subclass with the Paper Trail gem

76 Views Asked by At

In my Rails app, I have a parent class Assessment with various subclasses LanguageAssessment, MathsAssessment etc. Every model in the application has_papertrail as this is on ApplicationRecord. When an item with a LanguageAssessment is deleted, Papertrail tries to access the assessments table and throws an exception, because it doesn't exist—it should be looking at the language_assessments table. Is there a way to tell it this?

1

There are 1 best solutions below

0
dbugger On BEST ANSWER

From https://github.com/paper-trail-gem/paper_trail/issues/362

If you're using model inheritance for something other than STI you will need to override the base_class of the parent class like so:

class LanguageAssessment < Assessment
  has_paper_trail

  def self.base_class
    self
  end
end